exceptions in g++

Jonathan Wakely jwakely.gcc@gmail.com
Thu Sep 1 17:35:00 GMT 2011


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-defined (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; }
}



More information about the Gcc-help mailing list