Warnings for unhandled c++ exceptions?
Wesley W. Terpstra
terpstra@ito.tu-darmstadt.de
Mon Feb 3 19:16:00 GMT 2003
On Mon, Feb 03, 2003 at 04:11:07PM -0200, Alexandre Oliva wrote:
> On Feb 3, 2003, "Wesley W. Terpstra" <terpstra@ito.tu-darmstadt.de> wrote:
>
> > 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)
>
> /me thinks such a warning would be mostly useless
>
> I actually find this sad, but if you consider that most of the C++
> code out there, as well as the C library whose declarations are
> brought into C++, have no throw() declarations at all, you'd quickly
> drown into warning due to calling methods that could throw anything
> but that in reality don't, and it would be very difficult to tell what
> warnings are actually significant.
Yes, but you missed the fine print in my options' descriptions.
-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.
(by not included I meant not included in our throw clause)
-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
The first one does not warn about functions which might throw but don't
include a throw () clause. Nor does it warn about calling them.
The second will only warn about things defined within your translation unit.
... excepting inline methods of course... and I see that the libstdc++ does
this. Perhaps the above throw-clause-missing should be ignored for inlined
methods.
Therefore, these warnings will NOT be issued by including other people's
no-throw-declared headers. Only when misusing throw () declared methods and
writing bad methods yourself.
Neither warning is triggered by:
void foo(); // defined elsewhere and actually throws ints
void bar()
{
foo();
}
In a large enough software project, you probably won't be calling many of
these out-of-project methods (and such calls are suspect anyways), so the
warnings are still useful in the context you describe.
---
Wes
----- End forwarded message -----
More information about the Gcc
mailing list