This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: exceptions in g++
On 1 September 2011 17:53, Miles Bader wrote:
> Am I on crack, or should the following print "destroyed!" before being
> terminated by the uncaught exception?
It's implementation-defined.
The C++11 standard says:
"If no matching handler is found, the function std::terminate() is
called; whether or not the stack is
unwound before this call to std::terminate() is implementation-deïned (15.5.1)."
This allows a core file to be generated immediately, at the point
where the unhandled exception is thrown, which is much more useful for
debugging unhandled exceptions.
If you want to ensure the stack is unwound, put a catch(...) block in
main (and rethrow if you don't want to do anything else)
int main () {
try { f (); } catch(...) { throw; }
}