这是一个最小的例子:
[joel@maison various] (master *)$ cat throw.cpp #includeint main(int argc, char* argv[]) { throw("pouet pouet"); } [joel@maison various] (master *)$ ./a.out terminate called after throwing an instance of 'char const*' Aborted (core dumped)
阅读文档,似乎是默认的终止处理程序abort()
.我在中止手册页中找不到任何关于触发段错误的信息.
抛出异常并且不处理它abort()
会引发异常SIGABRT
.
您可以使用以下内容进行验证
#include#include #include extern "C" void handle_sigabrt(int) { std::cout << "Handling and then returning (exiting)" << std::endl; } int main() { signal(SIGABRT, &handle_sigabrt); throw("pouet pouet"); }
Demo