Warnings for unhandled c++ exceptions?

Bonzini bonzini@gnu.org
Mon Feb 3 15:24:00 GMT 2003


> int foo() throw (int)
> {
>     throw "this will abort -- why? I broke my promise, but no warning...";
> }
> ...
> catch (const char *s)

A warning might be desirable, but it is not an odd behavior, as the purpose
of the throw clause (aka exception specification) is exactly to abort if an
exception that's not mentioned there propagates above it.

"Whenever an exception is thrown and the search for a handler (15.3)
encounters the outermost block of a function with an
exception-specification, the function unexpected() is called (15.5.2) if the
exception-specification does not allow the exception. (15.4.8)."

"exception handling must be abandoned [...] when unexpected() throws an
exception which is not allowed by the previously violated
exception-specification, and std::bad_exception is not included in that
exception-specification." (15.5.1.1) "In such cases, void terminate(); is
called." (15.5.1.2)

Anyway I don't think the warning should be enabled by default as wide bodies
of C++ code don't use exception specifications.

Paolo




More information about the Gcc mailing list