EHsc vc EHa(同步异步异常处理) [英] EHsc vc EHa (synchronous vs asynchronous exception handling)

查看:1477
本文介绍了EHsc vc EHa(同步异步异常处理)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你能给出一个实际差异/含义的列表吗?我读了相关的MSDN文章,但我理解异步异常仍然有点朦胧。

Could you give a bullet list of practical differences/implication? I read relevant MSDN article, but my understanding asynchronous exceptions is still a bit hazy.

我使用Boost.Test编写一个测试套件,我的编译器发出警告EHa应启用:

I am writing a test suite using Boost.Test and my compiler emits a warning that EHa should be enabled:

警告C4535:calls _set_se_translator()requires / EHa

项目本身仅使用纯异常(来自STL),并且不需要/ EHa开关。我必须重新编译/ EHa开关,使测试套件正常工作吗?我的感觉是,我需要/ EHa试穿。

The project itself uses only plain exceptions (from STL) and doesn't need /EHa switch. Do I have to recompile it with /EHa switch to make the test suite work properly? My feeling is that I need /EHa for the test suit only.

谢谢新年快乐。

推荐答案

当您使用/ EHsc时,编译器将只会发出异常过滤器的代码,当它可以检测到包裹在try {}块中的代码可能会抛出一个C ++异常。异常过滤器确保在处理异常时解除堆栈时调用任何局部C ++对象的析构函数。它使RAII工作。

When you use /EHsc, the compiler will only emit code for exception filters when it can detect that the code wrapped in the try {} block might throw a C++ exception. An exception filter ensures that the destructor of any local C++ objects get called when the stack is unwound while handling an exception. It makes RAII work.

这是x86代码的优化,空间和时间,x64代码的空间。空间,因为它可以省略异常过滤器代码,这是适中的btw。时间,因为在x86它可以避免在进入try {}块时注册异常过滤器。非常适中btw。 x64使用不同的方式来查找异常过滤器,它是基于表的。

That's an optimization, space and time for x86 code, space for x64 code. Space because it can omit the exception filter code, which is modest btw. Time because on x86 it can avoid registering the exception filter upon entering the try {} block. Very modest btw. x64 uses a different way to find exception filters, it is table-based.

第一段中的关键短语是可能抛出C ++异常。在Windows上有其他来源的异常。像a中的/ EHa,异步异常由硬件引发。例如浮点异常,除以零,以及所有强大的访问冲突异常。但也特别是那种由可能交互的代码引发的异常。像托管代码,基本上是在VM中运行的任何东西。

The key phrase in the first paragraph is "might throw a C++ exception". On Windows there are other sources of exceptions. Like the "a" in /EHa, asynchronous exceptions that are raised by the hardware. Things like floating point exceptions, division by zero, and the all-mighty access violation exception. But also notably the kind of exceptions that are raised by code that you might interop with. Like managed code, basically anything that runs in a VM.

当你想让这些类型的异常时你的对象是安全的,那么你需要使用/ EHa,告诉编译器总是注册异常过滤器。

When you want to make your objects safe for these kind of exceptions as well then you'll need to use /EHa, that tells the compiler to always register the exception filter.

注意/ EHa的副作用,使catch(...)吞下所有异常。包括你永远不应该捕获的,如AV和SO。看看 __ try / __除非和_set_se_translator()如果这对你很重要。

Beware of a nasty side-effect of /EHa, it makes catch(...) swallow all exceptions. Including the ones you should never catch, like AV and SO. Look at __try/__except and _set_se_translator() if that's important to you.

这篇关于EHsc vc EHa(同步异步异常处理)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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