关于C ++中的结构化异常(SEH)应该知道什么? [英] What should I know about Structured Exceptions (SEH) in C++?

查看:204
本文介绍了关于C ++中的结构化异常(SEH)应该知道什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

解决方案

他们是Win32等效于Unix信号,让您捕获CPU异常,例如访问冲突,非法指令,除以零。



使用正确的编译器选项(/ Visual C ++的EHa),C ++异常使用相同作为堆栈展开的机制适用于C ++(用户)异常和SEH(OS)异常。



与C ++异常不同,SEH不是键入的,但都共享相同的数据结构它有一个异常代码(原因)以及关于什么代码故障以及在发生故障时保持的CPU寄存器的附加信息。请参阅 GetExceptionCode GetExceptionInformation 获取更多详细信息。



此外,SEH还具有第一次机会的处理方式,否则在解除之前处理​​异常会破坏所有本地变量。


What important points about Structured Exceptions should every C++ developer know?

解决方案

They are the Win32 equivalent to Unix signals, and let you catch CPU exceptions such as access violation, illegal instruction, divide by zero.

With the right compiler options (/EHa for Visual C++), C++ exceptions use the same mechanism as stack unwinding works properly for both C++ (user) exceptions and SEH (OS) exceptions.

Unlike C++ exceptions, SEH are not typed but all share the same data structure which has an exception code (the cause) and additional information on what code faulted and what the CPU registers held at the time of the fault. See GetExceptionCode and GetExceptionInformation for more details on this.

Also, SEH has "first-chance" handling, which allows you to log or otherwise handle the exception before unwinding destroys all the local variables.

这篇关于关于C ++中的结构化异常(SEH)应该知道什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆