C ++异常和结构化异常之间的区别 [英] Difference between a C++ exception and Structured Exception
问题描述
您实际上有三种机制:
- 由编译器实现的C ++异常(
try
/catch
) - 由Windows提供的结构化异常处理(SEH)(
__ try
/__除了
) - MFC异常宏(
TRY
,CATCH
- 建立在SEH / C ++异常之上 - 另请参见TheUndeadFish的注释)
C ++异常通常保证自动清理在堆栈解卷(即本地对象的析构函数运行)期间,其他机制不会。
只有当它们被明确抛出时才会发生C ++异常。结构化异常可能发生在许多操作中,例如由于未定义的行为,将无效指针传递给API,卸载内存映射文件的后备存储等等。
MFC确实引入了异常宏来支持异常,即使编译器没有实现它们。
Can someone explain the difference between a C++ exception and a structured exception in MFC?
You actually have three mechanisms:
- C++ exceptions, implemented by the compiler (
try
/catch
) - Structured Exception Handling (SEH), provided by Windows (
__try
/__except
) - MFC exception macros (
TRY
,CATCH
- built on top of SEH / C++ exceptions - see also TheUndeadFish's comment)
C++ exceptions usually guarantee automatic cleanup during stack unwinding (i.e. destructors of local objects run), the other mechanisms don't.
C++ exceptions only occur when they are explicitly thrown. Structured Exceptions may occur for many operations, e.g. due to undefined behavior, passing invalid pointers to APIs, unmounting the backing store of a memory mapped file, and many more.
MFC did introduce the exception macros to support exceptions even if compilers didn't implement them.
这篇关于C ++异常和结构化异常之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!