void test1()
{
try
{
try
{
throw runtime_error("asdfasdf");
}
catch(std::exception &e)
{
throw e;
}
}
catch(std::runtime_error &e)
{
throw e;
}
catch(std::exception &e)
{
cout<<e.what()<<endl;
}
}
這段代碼都有輸出:
在vc2010裏輸出 仍然是 asdfasdf
但是mingw4.5.2裏輸出則是std::exception
當runtime_error 被扔出來的時候,exception& e接住了,但是 e再拋出的時候,因爲已經是exception的異常了,所以只能被第三個catch接住.