Expand description
The thread error mode aspect.
The thread error mode decides whether a hard device error – the classic
absent-removable-drive case – raises a modal dialog or fails the call. A
thread-pool worker’s mode is 0, meaning the critical-error handler is
enabled, so a blocking call remoted onto shared infrastructure can put a
dialog on a thread the whole process depends on.
§This aspect is both capturable and declarable, deliberately
Unlike the others it appears in both halves of the crate’s decomposition. It is readable, so a caller may capture the submitting thread’s value and transplant it; and it is the aspect consumers most often want to override with a policy of their own. Offering only one of those would bake one consumer’s answer into a platform layer: a consumer running on shared threads will force the dialog-suppressing bits, while a consumer owning a private thread, where a modal dialog is its own problem and nobody else’s, is entitled to the opposite choice.
§Why the alignment bit is not representable
ThreadErrorMode can hold only the three bits SetThreadErrorMode
accepts. SEM_NOALIGNMENTFAULTEXCEPT is excluded because it is rejected
per-thread – and, measured, an invalid bit fails the whole call rather
than being dropped from it. A type that could represent it would let a caller
combine it with valid bits and silently lose the entire change, so this is a
case for a type that cannot express the invalid state rather than a runtime
check nobody expected to fail. See
windows-platform-probes,
which pins the measurement as a test.
§Example
use windows_thread_ambient_sys::ThreadErrorMode;
let entry = ThreadErrorMode::capture()?;
let mode = ThreadErrorMode::FAIL_CRITICAL_ERRORS
.union(ThreadErrorMode::NO_OPEN_FILE_ERROR_BOX);
let guard = mode.apply()?;
assert!(ThreadErrorMode::capture()?.contains(ThreadErrorMode::FAIL_CRITICAL_ERRORS));
// Release explicitly. Dropping the guard also restores, but discards any
// failure to do so, because a destructor has no caller to report to.
guard.release()?;
assert_eq!(ThreadErrorMode::capture()?, entry);Structs§
- Apply
Error - Windows refused to install a thread error mode.
- Error
Mode Guard - Holds an installed error mode until it is released.
- Restore
Error - Windows refused to restore the thread’s entry error mode.
- Thread
Error Mode - A thread error mode, restricted to the bits Windows accepts per thread.
- Unsupported
Bits - A raw value contained bits the per-thread error mode does not accept.