This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Warnings for unhandled c++ exceptions?


> 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



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]