c++禁止堆栈框架下的异常
C++ disable exceptions below stack frame
是否有一种方法可以使异常不传播到某个堆栈帧之上,同时不丢失堆栈信息?
,
int foo() {
throw 3;
}
int bar() {
// do something here
foo();
}
int main() {
try {
bar();
} catch(...) {
std::cout << "Caught";
}
}
我希望这个在'throw 3'调用时终止,而不能被main捕获。
这可能吗?
只需在函数声明和定义后添加throw()
#include <iostream>
void* g_pStackTrace = NULL;
int foo() throw();
int foo() throw() {
g_pStackTrace = <stack_trace_function_call>;
throw 3;
}
int bar() {
// do something here
foo();
return 0;
}
int main() {
bar();
if (g_pStackTrace != NULL)
{
// Work with our stack
}
}
这将阻止你的throw调用
不同操作系统的堆栈跟踪函数
backtrace_symbols(3)
- linux, mac osx
CaptureStackBackTrace(...)
- windows
现场演示
相关文章:
- 处理多个异常集合的C++方法
- 我在c++代码中生成了一个运行时#3异常
- 孤立代码块在结构中引发异常
- C++中的赋值发生,尽管右侧出现异常
- 从构造函数抛出异常时如何克服内存泄漏
- 异常属于C++中的线程还是进程
- 当类定义不可见时捕获异常
- 在没有Xcode的情况下在Mac捆绑包中嵌入框架
- 引发异常:读取访问冲突**dynamicArray**为0x1118235.发生
- 为什么异常不退出程序?
- 为什么我应该在异常处理中使用std::cerr而不是std::cout
- catch框架有没有办法比较流或文件
- 如何修复链表类实现的未处理异常0xDDDDDDDD
- 关于:C++中异常对象的范围:为什么我没有得到副本?
- 是什么导致了Unity 3D中的"错误线程异常"?
- 如何将strftime中的格式错误作为异常捕获
- 有没有任何方法可以在C++中导致整个堆栈框架展开?(使用异常除外)
- c++禁止堆栈框架下的异常
- CppUTest单元测试框架多定义异常
- CLR 有胖或小的异常框架