【发布时间】:2015-12-29 16:19:54
【问题描述】:
我有这个代码:
#include <iostream>
#include <exception>
class TestException : public std::exception
{
public:
char const* what() const throw() override { return msg_.c_str(); }
protected:
std::string & message() throw() { return msg_; }
private:
std::string msg_;
};
void ThrowIt()
{
throw TestException();
}
int main()
{
ThrowIt();
}
在使用 Visual Studio 编译的 Windows 上的 Release 或 Debug 中运行此程序会导致程序终止,在 Linux 机器上使用 GCC 编译时也是如此,结果是:
在抛出“TestException”实例后调用终止
what(): 中止
一旦捕获到未处理的异常,两者都会终止程序。这种行为是严格的系统特定的还是标准规定的?有没有一种跨平台的方法可以让我将catch 未处理的每个异常重新路由到处理程序,而不仅仅是终止程序?
【问题讨论】:
标签: c++ c++11 exception-handling g++ visual-studio-2015