当前位置:首页 > 开发 > 操作系统 > 正文

EHsc vc EHa (synchronous vs asynchronous exception handling)

发表于: 2014-03-18   作者:aigo   来源:转载   浏览次数:
摘要: 原文:http://stackoverflow.com/questions/4573536/ehsc-vc-eha-synchronous-vs-asynchronous-exception-handling   When you use /EHsc, the compiler will only emit code for exception filters when it can

原文:http://stackoverflow.com/questions/4573536/ehsc-vc-eha-synchronous-vs-asynchronous-exception-handling

 

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.

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.

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.

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.

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 (synchronous vs asynchronous exception handling)

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

编辑推荐
  这段时间在做的案子有一些同步和异步的web services的处理的问题,在网上看到Paolo(Microsoft,
public void consumeAndForgetAllExceptions(){ try { ...some code that throws exceptions } catc
Note: It is very important to just use the throw statement, rather than throw ex. If you have
One of the problems with exception handling is knowing when and how to use it. In this articl
在Google学术上搜到一篇有意思但也很有争议的文章,题为《Best Practices for Exception Handling》
http://www.softwaretestinghelp.com/exception-handling-framework-selenium-tutorial-19/ In last
同步(synchronous) IO和异步(asynchronous) IO,阻塞(blocking) IO和非阻塞(non-blocking)I
添加引用: 获取Facade类 ExceptionManager ExManager = EnterpriseLibraryContainer.Current.GetIns
三、 TRY CATCH & Return 在上面一节中,我通过RAISERROR重写了创建User的Stored procedure,实际上
对于所有的开发人员来说,Exception Handling是我们每天都要面对的事情。对于基于Source Code的Exce
版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号