This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Warnings for unhandled c++ exceptions?
On Mon, Feb 03, 2003 at 02:21:41PM -0500, Mark Mielke wrote:
> On Mon, Feb 03, 2003 at 02:13:45PM +0100, Wesley W. Terpstra wrote:
> > I find this feature of Java remarkably useful as it helps to detect sloppy
> > exception handling, which is brutal to find in C++. I do not desire to
> > change the C++ language much; I like it just how it is, but I think an
> > optional warning would be useful during development under g++.
>
> Even in Java, they recognized that sometimes, this ability, is more trouble
> than it is worth. Consider sub classes of java.lang.RuntimeException.
Indeed, but as you might notice, my proposal does not make 'runtime'
exceptions (such as 'new' runs out of memory) and many other cases generate
a warning. If it is not an exception explicitly thrown or explicitly listed
in a called function's throw clause, the warning is not triggered. So
division by zero, etc, or anything hidden by a library is not warned.
Plus, the warning is entirely optional and not default.
> I don't think there is a 'right' answer to this problem. Java leans towards
> one side, while C++ leans towards the other side. It seems wrong to me to
> encourage C++ users to lean the wrong way by presenting them with a 'Java'
> style warning. C++ users need to be familiar with C++ practices. If they
> are not, they will never excel at C++.
I did not mean to imply that people should not use and know C++ practices.
There are lots of warnings for behaviours that are *legal* C++ but
unethical. And this warning is not something I would suggest including in
-Wall.
My primary goals for this warning were solely: bug tracking and consistency
verification. Nothing more.
I have no designs to change the exception paradigm of C++.
> I would be against such a warning message. It is cute, but impractical.
I disagree that it is impracticle. With a really large project, consistency
of throw can be really hard to verify.
---
Wes