From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9497 invoked by alias); 3 Feb 2003 19:14:17 -0000 Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org Received: (qmail 9489 invoked from network); 3 Feb 2003 19:14:17 -0000 Received: from unknown (HELO kontiki.ito.tu-darmstadt.de) (130.83.198.42) by 172.16.49.205 with SMTP; 3 Feb 2003 19:14:17 -0000 Received: from gin (gin.internal [10.2.0.251]) by kontiki.ito.tu-darmstadt.de (Postfix) with SMTP id 60FD327C70 for ; Mon, 3 Feb 2003 20:14:16 +0100 (CET) Received: by gin (sSMTP sendmail emulation); Mon, 3 Feb 2003 20:14:16 +0100 From: "Wesley W. Terpstra" Date: Mon, 03 Feb 2003 19:14:00 -0000 To: gcc@gcc.gnu.org Subject: Re: Warnings for unhandled c++ exceptions? Message-ID: <20030203191416.GC26857@ito.tu-darmstadt.de> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.3.28i X-SW-Source: 2003-02/txt/msg00105.txt.bz2 On Mon, Feb 03, 2003 at 09:05:59AM -0800, Joe Buck wrote: > On Mon, Feb 03, 2003 at 02:13:45PM +0100, Wesley W. Terpstra wrote: > > Is there a compiler flag for g++ which would warn on these code snippets: > > > > 1. > > > > void foo() > > { > > throw 4; > > } > > > > Warning: Exception 'int' must be caught, or it must be declared in throw () > > clause of this method. > > But there is no such requirement in C++. If there is no throw() directive, > it means that anything can be thrown. I understand this, but it would still be useful to have an option to track bugs. No one is forced to use this option, and those who choose to say: 'the above code is unethical' can write better code > > 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++. > > Any such option cannot use the word "must", because it implies a language > requirement that is not present. Ok, fair enough, how about "This option helps detect unhandled exceptions by reporting violations of an extra-language constraint that all throwable exceptions should be declared in the prototype". And a warning like "Warning: method can throw an exception undeclared in it's prototype, and you said you didn't want this to be allowed." > What you're seeing below is standard C++ behavior. If a function > declares that it will only throw int, but it throws something else, > it immediately terminates. That's the way C++ assures that promises > like throw(int) are kept. Someone pointed this out already. That was a misunderstanding of mine. (I actually expected gcc to try to convert the const char* to int) --- Wes