I have a problem with a c++ library that I develop: I defined my own exception class (that basically only contains a string to return for the what() call) and when an exception is not caught, the goal is that the operating system would print the message from what() and terminate. This works well on Linux but on osX, the exception message is not shown (ie it directly terminates without printing anything).
So, am I correctly assuming that uncaught exceptions would lead to what() followed by a termination? What should I do on osX so the message would be shown? (knowing that I don’t like the idea of setting an exception handler, since this imposes the user of the library to do it)
Thanks!
Mathias
No. The standards don’t require uncaught exceptions to print out
what(). In fact, they make it pretty hard (but not impossible) to write a conforming implementation that always does so.There’s really no good way to do exactly what you want to do (print out the
what(), only if the implementation isn’t going to do so in this case, then carry on toterminate()as if the exception had never been caught). But that probably isn’t what you really want.This is probably what you want:
If you really want to, say,
_exitorabort(or eventerminate) instead ofexiting, you can do that of course. But if you don’t know, you probably wantexit.Meanwhile:
You’re writing a library? And you want your library to be able to terminate the process behind the application’s back?
That’s probably a very bad idea.
But if you really do want to do it, the same code above will work, you just have to wrap it around the entry points to your library instead of around
main.