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?


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


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