在Visual Studio 2010中混合使用异常处理模型有什么后果? [英] What are the consequences of mixing exception handling models in Visual Studio 2010?

查看:100
本文介绍了在Visual Studio 2010中混合使用异常处理模型有什么后果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个内置的第三方静态库,其中Enable C++ Exceptions设置为(未指定/EH标志).从启用C ++异常(/EHa)构建的代码中调用它会有什么后果?如果从库中引发了结构化异常,是否可以可靠地调用主应用程序提供给_set_se_translator的函数? (我的实验表明这样做会,但是只是想知道这是否是定义的行为).

I have third-party static library built with Enable C++ Exceptions set to No (/EH flag not specified). What are the consequences to calling into it from code built with C++ exceptions enabled (/EHa)? If a Structured Exception is thrown from within the library, will the function provided to _set_se_translator by the main application be reliably called? (My experiments show that it will, but just wondering if this is defined behavior).

混合/EH异常处理模型时还有其他考虑事项吗?

Are there any other considerations when mixing /EH exception handing models?

推荐答案

调用未启用异常的 代码不会产生任何问题-这与调用外部C没什么不同功能或类似性质的东西.

Calling into code which does not have exceptions enabled shouldn't produce any problems -- this is no different than calling an external C function or something of that nature.

从未启用异常的代码中调用(进入启用异常的代码)可能不会在禁用异常的代码中包含正确的堆栈展开语义,这意味着您将破坏该变量的不变量代码,除非它是专门为处理异常而设计的. (例如,某些库(例如ANTLR)在一个块中分配所有内存,并让用户代码一次释放所有内容,即使它们本身不使用异常,也可以使用异常而不会泄漏).

Calling from code which does not have exceptions enabled (into exception enabled code) will probably not contain the correct stack unwinding semantics in the exception disabled code, which means you'll be breaking invariants of that code, unless it was specifically designed to work with exceptions. (For example, some libraries (e.g. ANTLR) allocate all memory in a block and have the user code free everything at once, allowing exceptions to be used without leaking even though they themselves do not use exceptions).

Raymond Chen 上有一篇文章关于C ++异常处理如何在MSVC ++上工作的内幕.长话短说,它是建立在Windows SEH之上的.因此,它的行为应类似于如果您在例如中抛出SEH异常时所发生的情况. C代码. (但是,我自己尚未对此进行验证)

Raymond Chen has quite an article about the innards of how C++'s exception handling works on MSVC++. Long story short, it's built on top of Windows' SEH. Therefore it should behave similarly to what happens if you throw a SEH exception in e.g. C code. (However, I've not verified this myself)

这篇关于在Visual Studio 2010中混合使用异常处理模型有什么后果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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