Peter Schuller wrote:
Hello, In C++, I would like to take advantage of throw() clauses for their documentative value (and possible future value if gcc implements checked exceptions). At the same time however, I want to *usefully* handle the throwing of unexpected exceptions (where "useful" includes being able to inspect the exception in question). Toward this end I have a couple of questions that my Googling has not helped: * gcc has an option -fno-enforce-eh-specs which has pretty much the effect I would want because it allows for generic top-level catch() statements that exit with a useful error message. The man-page says the compiler "will still optimize based on the exception specifications". Should I interpret this as saying it is *unsafe* to enable this option with code that *does* throw unexpected exceptions? If not, is it guaranteed to *be* safe?
the code will be unsafe. If an exception is thrown out of a throw () function, the effects will be undefined.
* providing user-defined behavior for std::unexpected() (as exemplified at [1]) would be an alternative aswell - *if* I can obtain a reference to the exception during runtime. Is there some way (standard or gcc-specific) to do this?
This is target specific. Note that the exception object might be foreign (a non C++ object). Look at unwind.h for details.
nathan -- Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC nathan@xxxxxxxxxxxxxxxx :: http://www.planetfall.pwp.blueyonder.co.uk