From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4990 invoked by alias); 3 Feb 2003 13:13:47 -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 4982 invoked from network); 3 Feb 2003 13:13:46 -0000 Received: from unknown (HELO kontiki.ito.tu-darmstadt.de) (130.83.198.42) by 172.16.49.205 with SMTP; 3 Feb 2003 13:13:46 -0000 Received: from gin (gin.internal [10.2.0.251]) by kontiki.ito.tu-darmstadt.de (Postfix) with SMTP id AC37827C70 for ; Mon, 3 Feb 2003 14:13:45 +0100 (CET) Received: by gin (sSMTP sendmail emulation); Mon, 3 Feb 2003 14:13:45 +0100 From: "Wesley W. Terpstra" Date: Mon, 03 Feb 2003 13:13:00 -0000 To: gcc@gcc.gnu.org Subject: Warnings for unhandled c++ exceptions? Message-ID: <20030203131345.GA25136@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/msg00072.txt.bz2 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. 2. void foo() throw (int) { throw 4; } void bar() { foo(); } Warning: ... bar ... 'int' must be caught or ... ---------------------------- 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++. Since g++ can also invoke Java methods, and in turn be called by them, it also makes sense that g++ should be able to maintain the Java-style guarantees about only throwing what one declares throwable. Is there some undocumented -W option to turn this warning on? Is there some patch someone has I can apply to add this feature? And if not ... shouldn't there be? ---------------------------- Relatedly, I'm sure you are aware of this odd behaviour: (debian gcc 3.2.2-0pre5) int foo() throw (int) { throw "this will abort -- why? I broke my promise, but no warning..."; } int main() { try { foo(); } catch (const char* s) { // should catch here... } catch (int x) { // in case of a weird conversion } return 0; } ---------------------------- Thanks for your time. --- Wes