C++ 在OSX中,C++;未处理的异常不会自动打印what()的输出
以这段代码为例:C++ 在OSX中,C++;未处理的异常不会自动打印what()的输出,c++,macos,exception,C++,Macos,Exception,以这段代码为例: #include <exception> int main() { throw std::exception(); return 0; } 然而,当在OS X Mountain Lion上编译和运行(同时使用GCC和clang)时,我得到了以下有用得多的输出: terminate called after throwing an instance of 'std::exception' what(): std::exception Aborte
#include <exception>
int main()
{
throw std::exception();
return 0;
}
然而,当在OS X Mountain Lion上编译和运行(同时使用GCC和clang)时,我得到了以下有用得多的输出:
terminate called after throwing an instance of 'std::exception'
what(): std::exception
Aborted (core dumped)
libc++abi.dylib: terminate called throwing an exception
有没有一种方法可以使OS X默认在未处理的异常上打印what()的输出?值得一提的是,这在OS X Mavericks中对我很有用:
$ echo '
> #include <stdexcept>
>
> int main()
> {
> throw std::runtime_error("oh no");
> return 0;
> }
> ' | g++ -x c++ - ; ./a.out
libc++abi.dylib: terminating with uncaught exception of type std::runtime_error: oh no
Abort trap: 6
没有太多帮助,但在调试模式(g++)下编译OnLion似乎可以做您想要做的事情,所以我想知道苹果是否有助于重定向这些事情。它似乎在控制台的用户诊断报告下生成了一个调试日志。捕获它并打印消息。未处理的异常是设计错误。您可以使用Boost中的诊断信息:try{….}catch(…){std::cout
libc++abi.dylib: terminating with uncaught exception of type std::exception: std::exception
Abort trap: 6