也许我今天没有喝够咖啡。下面的程序应该捕获std::runtime_error并打印“i catch The runtime_eerror”,对吗?
事实并非如此。该程序没有捕获std::runtime_error,而是打印“为什么我无法捕获runtime_eError”?
我在这里做错了什么?为什么我没有捕捉到std::runtime_error?
这是Clang(请参见代码下面的环境信息)。
#include <iostream>
#include <exception>
int main(int argc, const char * argv[])
{
try
{
throw new std::runtime_error( "a runtime_error was thrown" );
}
catch ( const std::runtime_error& e )
{
std::cout << "i caught the runtime_error" << std::endl;
}
catch ( ... )
{
std::cout << "why was i unable to catch the runtime_error?" << std::endl;
}
return 0;
}
OS X 10.9.5上的Xcode 5.1.1
comp:~ usrn$ clang --version
Apple LLVM version 5.1 (clang-503.0.38) (based on LLVM 3.4svn)
Target: x86_64-apple-darwin13.4.0
Thread model: posix
comp:~ usern$