这在C++中被认为是很好的编程实践:
try {
// some code
}
catch(someException) {
// do something
}
catch (...)
{
// left empty <-- Good Practice???
}
Run Code Online (Sandbox Code Playgroud) 说我有:
try
{
externalLibrary::doSomething();
}
catch (std::exception &e)
{
//yay I know what to do
}
catch (...)
{
//darn, I've no idea what happened!
}
Run Code Online (Sandbox Code Playgroud)
在某些没有调试信息的外部库中,可能会出现异常并且您不知道它来自何处或原因的情况.有没有办法找到抛出的内容,或以其他方式获取与之相关的任何数据?他们可能会这样做:
throw myStupidCustomString("here is some really useful information");
Run Code Online (Sandbox Code Playgroud)
但我永远不会知道我是否抓住了 ...
如果重要的话,在MSVC++ 2008中工作.