【发布时间】:2014-09-18 07:50:43
【问题描述】:
在C++中,我们可以通过catch(bad_cast& ex)获取异常信息,然后输出ex.what()的内容
try{
//…
}catch(std::bad_alloc& e)
{
cout << “Catch bad alloc exception ” << e.what() << endl;
}
catch(std::bad_cast& e)
{
cout << “Catch bad alloc exception ” << e.what() << endl;
}
catch(std::bad_exception& e)
{
cout << “Catch bad alloc exception ” << e.what() << endl;
}
// catch more exception types here
// …
catch(...)
{
// how to get the content of unknown exception?
}
如何从catch(...)获取异常信息?
【问题讨论】:
-
简而言之:你不能可靠。