GitHub - ArthurSonzogni/cppcms: CppCMS Framework
cpp
#include <booster/backtrace.h>
#include <iostream>
int foo()
{
throw booster::runtime_error("My Error");
return 10;
}
int bar()
{
return foo()+20;
}
int main()
{
try {
std::cout << bar() << std::endl;
}
catch(std::exception const &e)
{
std::cerr << e.what() << std::endl;
std::cerr << booster::trace(e);
}
}
输出:
My Error
00007FFCA447BE91: booster::stack_trace::trace +0x31
00007FF6BF2F491D: booster::backtrace::backtrace +0x7d
00007FF6BF2F4CF5: booster::runtime_error::runtime_error +0x35
00007FF6BF2F1CEC: foo +0x3c
00007FF6BF2F1D3B: bar +0xb
00007FF6BF2F1D6C: main +0x1c
00007FF6BF2F7779: invoke_main +0x39
00007FF6BF2F7622: __scrt_common_main_seh +0x132
00007FF6BF2F74DE: __scrt_common_main +0xe
00007FF6BF2F780E: mainCRTStartup +0xe
00007FFD17127614: BaseThreadInitThunk +0x14
00007FFD181C26A1: RtlUserThreadStart +0x21