且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

C++ try-catch 块不捕获硬件异常

更新时间:2023-11-29 14:29:46

这是否取决于处理器

Is this dependent of processor

是的.操作系统仅将硬件陷阱映射到结构化异常,它没有添加逻辑来检测硬件没有检测到的条件.(另一方面,JVM 或 CLR 等托管框架通常会添加逻辑.在软件中捕获这些当然会带来性能损失,而硬件陷阱逻辑是免费的,除非陷阱实际发生.)

Yup. The OS only maps hardware traps to structured exceptions, it doesn't add logic to detect conditions that the hardware doesn't. (On the other hand, managed frameworks such as the JVM or CLR often do add logic. Catching these in software of course carries a performance penalty, while hardware trap logic is free unless the trap actually occurs.)

现在,这并不是说您不能在 x86 处理器上接收 EXCEPTION_INT_OVERFLOW.但是条件不是您所期望的——在添加过程中仅仅环绕不会导致陷阱.请参阅 Raymond Chen 的博客条目:

Now, this isn't to say that you cannot receive EXCEPTION_INT_OVERFLOW on x86 processors. But the conditions are not what you expect -- mere wraparound during addition does not cause a trap. See Raymond Chen's blog entry:

  • In the red corner, EXCEPTION_INT_DIVIDE_BY_ZERO and STATUS_INTEGER_DIVIDE_BY_ZERO; and in the blue corner, EXCEPTION_INT_and STATUS_INTEGER_OVERFLOW