This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Warnings for unhandled c++ exceptions?
- From: "Wesley W. Terpstra" <terpstra at ito dot tu-darmstadt dot de>
- To: gcc at gcc dot gnu dot org
- Cc: Bonzini <bonzini at gnu dot org>
- Date: Mon, 3 Feb 2003 17:45:26 +0100
- Subject: Re: Warnings for unhandled c++ exceptions?
- References: <002601c2cb78$2a3efbc0$29dd1d97@bonz>
On Mon, Feb 03, 2003 at 12:34:06PM +0100, Bonzini wrote:
> > 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.
Ahh. That makes sense. That is at least some guarantee.
> Anyway I don't think the warning should be enabled by default as wide bodies
> of C++ code don't use exception specifications.
I never suggested is as a default.
I suggested an optional flag to be used for compiler-assisted bug-tracking
and quality code writing. (refer to the earlier portion of the message)
... especially since most (all?) of these errors are visible at compile-time.
Perhaps there should be two flags:
-Wthrow-clause-violated
If a method throws an exception which is not listed in it's
throw () clause, or calls a method whose throw clause is not
handled or not included, generate a warning.
-Wthrow-clause-missing
If a method throws an exception or calls a method which
declares a throw clause, but has no throw-clause itself,
a warning is generated.
Implies -Wthrow-clause-violated
I only suggest this if some does not already have a patch floating around.
I presume someone else has already requested this functionality?
google didn't turn up much because the keywords are ambiguous.
---
Wes