Platform SDK: Debugging and Error Handling

SetErrorMode

The SetErrorMode function controls whether the system will handle the specified types of serious errors, or whether the process will handle them.

UINT SetErrorMode(
  UINT uMode   // process error mode
);

Parameters

uMode
[in] Specifies the process error mode. This parameter can be one or more of the following values.
Value Action
0 Use the system default, which is to display all error dialog boxes.
SEM_FAILCRITICALERRORS The system does not display the critical-error-handler message box. Instead, the system sends the error to the calling process.
SEM_NOALIGNMENTFAULTEXCEPT RISC: The system automatically fixes memory alignment faults and makes them invisible to the application. It does this for the calling process and any descendant processes.

This flag has no effect on x86 processors.

SEM_NOGPFAULTERRORBOX The system does not display the general-protection-fault message box. This flag should only be set by debugging applications that handle general protection (GP) faults themselves with an exception handler.
SEM_NOOPENFILEERRORBOX The system does not display a message box when it fails to find a file. Instead, the error is returned to the calling process.

Return Values

The return value is the previous state of the error-mode bit flags.

Remarks

Each process has an associated error mode that indicates to the system how the application is going to respond to serious errors. A child process inherits the error mode of its parent process.

RISC: On some non-x86 processors misaligned memory references cause an alignment fault exception. The SEM_NOALIGNMENTFAULTEXCEPT flag lets you control whether the system automatically fixes such alignment faults, or makes them visible to an application.

MIPS: On a MIPS computer, an application must explicitly call SetErrorMode with the SEM_NOALIGNMENTFAULTEXCEPT flag to have the system automatically fix alignment faults. The default setting is for the system to make alignment faults visible to an application.

Alpha: On an ALPHA computer, you control the alignment fault behavior by setting the EnableAlignmentFaultExceptions value in the HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager registry key as follows.

Value Meaning
0 Automatically fix alignment faults. This is the default.
1 Make alignment faults visible to the application. You must call SetErrorMode with SEM_NOALIGNMENTFAULTEXCEPT to have the system automatically fix alignment faults.

x86: On an x86 computer, the system does not make alignment faults visible to an application. Therefore, specifying the SEM_NOALIGNMENTFAULTEXCEPT flag on an x86 computer is not an error, but the system is free to silently ignore and not properly preserve the flag. This means that code sequences such as the following are not always valid on x86 computers:

    SetErrorMode(SEM_NOALIGNMENTFAULTEXCEPT); 
    fuOldErrorMode = SetErrorMode(0); 
    ASSERT(fuOldErrorMode == SEM_NOALIGNMENTFAULTEXCEPT); 

Requirements

  Windows NT/2000: Requires Windows NT 3.1 or later.
  Windows 95/98: Requires Windows 95 or later.
  Header: Declared in Winbase.h; include Windows.h.
  Library: Use Kernel32.lib.

See Also

Error Handling Overview, Error Handling Functions