【发布时间】:2023-03-17 21:42:01
【问题描述】:
class ScopedShit
{
public:
ScopedShit() {
cout << "ScopedShit()" << endl;
}
~ScopedShit() {
cout << "~ScopedShit()" << endl;
}
};
void foo()
{
ScopedShit ss;
int x = 0;
int y = 5 / x;
}
int main()
{
__try {
foo();
}
__except(true) {
cout << "Continuing..." << endl;
}
}
输出:
ScopedShit()
继续...
我正在阅读这篇文章 http://www.codeproject.com/Articles/2126/How-a-C-compiler-implements-exception-handling,其中解释了:
但在它(异常处理程序)调用catch块之前(它知道catch的地址 来自 funcinfo 结构的块,参见图 4),它必须执行堆栈 unwinding: 清理下面函数的栈帧 函数的框架。堆栈框架的清理涉及很少 复杂性:异常处理程序必须找到所有本地对象 异常发生时帧上的函数并调用 他们的析构函数。
我错过了什么吗?
【问题讨论】: