Difference between a C++ exception and Structured Exception(C++ 异常和结构化异常之间的区别)
问题描述
有人能解释一下 C++ 异常和 MFC 中的结构化异常之间的区别吗?
Can someone explain the difference between a C++ exception and a structured exception in MFC?
推荐答案
你其实有三种机制:
- C++ 异常,由编译器实现 (
try/catch) - Windows 提供的结构化异常处理 (SEH) (
__try/__except) - MFC 异常宏(
TRY、CATCH- 建立在 SEH/C++ 异常之上 - 另见 TheUndeadFish 的评论)
- 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++ 异常通常保证在堆栈展开期间自动清理(即运行本地对象的析构函数),而其他机制则不能.
C++ exceptions usually guarantee automatic cleanup during stack unwinding (i.e. destructors of local objects run), the other mechanisms don't.
C++ 异常仅在显式抛出时发生.许多操作可能会出现结构化异常,例如由于未定义的行为、向 API 传递无效指针、卸载内存映射文件的后备存储等等.
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 确实引入了异常宏来支持异常,即使编译器没有实现它们.
MFC did introduce the exception macros to support exceptions even if compilers didn't implement them.
这篇关于C++ 异常和结构化异常之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:C++ 异常和结构化异常之间的区别
基础教程推荐
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- CString 到 char* 2021-01-01
