SetErrorMode

  windows 在默认情况下会接管应用程序出现的错误 比如内存访问异常 ,那么就会弹出个对话框来

如果应用程序要自己处理这些错误的话 那么就要使用这个API

SetErrorMode function

1 out of 6 rated this helpful - Rate this topic

Controls whether the system will handle the specified types of serious errors or whether the process will handle them.

Syntax

C++
UINT WINAPI SetErrorMode(
  _In_  UINT uMode
);

Parameters

uMode [in]

The process error mode. This parameter can be one or more of the following values.

Value Meaning
0

Use the system default, which is to display all error dialog boxes.

SEM_FAILCRITICALERRORS0x0001

The system does not display the critical-error-handler message box. Instead, the system sends the error to the calling process.

Best practice is that all applications call the process-wide SetErrorMode function with a parameter of SEM_FAILCRITICALERRORS at startup. This is to prevent error mode dialogs from hanging the application.

SEM_NOALIGNMENTFAULTEXCEPT0x0004

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 feature is only supported by certain processor architectures. For more information, see the Remarks section.

After this value is set for a process, subsequent attempts to clear the value are ignored.

SEM_NOGPFAULTERRORBOX0x0002

The system does not display the Windows Error Reporting dialog.

SEM_NOOPENFILEERRORBOX0x8000

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 value

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. To retrieve the process error mode, use the GetErrorMode function.

Because the error mode is set for the entire process, you must ensure that multi-threaded applications do not set different error-mode flags. Doing so can lead to inconsistent error handling.

The system does not make alignment faults visible to an application on all processor architectures. Therefore, specifying SEM_NOALIGNMENTFAULTEXCEPT is not an error on such architectures, but the system is free to silently ignore the request. This means that code sequences such as the following are not always valid on x86 computers:

C++
SetErrorMode(SEM_NOALIGNMENTFAULTEXCEPT); 
fuOldErrorMode = SetErrorMode(0); 
ASSERT(fuOldErrorMode == SEM_NOALIGNMENTFAULTEXCEPT);
Itanium:  An application must explicitly call SetErrorMode with SEM_NOALIGNMENTFAULTEXCEPT to have the system automatically fix alignment faults. The default setting is for the system to make alignment faults visible to an application.
Visual Studio 2005:  When declaring a pointer to a structure that may not have aligned data, you can use the __unaligned keyword to indicate that the type must be read one byte at a time. For more information, see Windows Data Alignment.
Windows 7:  

Callers should favor SetThreadErrorMode over SetErrorMode since it is less disruptive to the normal behavior of the system.

Requirements

Minimum supported client

Windows XP [desktop apps only]

Minimum supported server

Windows Server 2003 [desktop apps only]

Header

WinBase.h (include Windows.h)

Library

Kernel32.lib

DLL

Kernel32.dll

转载于:https://my.oschina.net/sincoder/blog/87838

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值