4

次のコードを見てください。

#include <exception>

int main()
{
    throw std::exception();
    return 0;
}

Ubuntu Linuxでgccを使用してこれをコンパイルして実行すると、次の役立つ出力が得られます。

terminate called after throwing an instance of 'std::exception'
what():  std::exception
Aborted (core dumped)

ただし、コンパイルしてOS X Mountain Lion(GCCとclangの両方を使用)で実行すると、次のような、あまり役に立たない出力が得られます。

libc++abi.dylib: terminate called throwing an exception

未処理の例外でwhat()の出力を出力するようにOS Xをデフォルトにする方法はありますか?

4

1 に答える 1

0

価値があるのは、これが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

だから、Apple はあなたのためにそれを修正しようとしているだけだと思います。

編集:また、なぜあなたの例もテストしなかったのかわかりませんが、それも同様に機能します:

g++/clang から:

libc++abi.dylib: terminating with uncaught exception of type std::exception: std::exception
Abort trap: 6
于 2014-01-22T05:31:27.607 に答える