From: Joe Buck <jbuck@synopsys.com>
To: "Wesley W. Terpstra" <terpstra@ito.tu-darmstadt.de>
Cc: gcc@gcc.gnu.org
Subject: Re: Warnings for unhandled c++ exceptions?
Date: Mon, 03 Feb 2003 17:07:00 -0000 [thread overview]
Message-ID: <20030203090559.A20872@synopsys.com> (raw)
In-Reply-To: <20030203131345.GA25136@ito.tu-darmstadt.de>; from terpstra@ito.tu-darmstadt.de on Mon, Feb 03, 2003 at 02:13:45PM +0100
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 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.
> Relatedly, I'm sure you are aware of this odd behaviour:
> (debian gcc 3.2.2-0pre5)
You should be aware of this odd behavior, too, if you want to pass yourself
off as a C++ programmer. :-)
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.
> 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
--
Q. What's more of a headache than a bug in a compiler.
A. Bugs in six compilers. -- Mark Johnson
next prev parent reply other threads:[~2003-02-03 17:07 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-02-03 13:13 Wesley W. Terpstra
2003-02-03 17:07 ` Joe Buck [this message]
2003-02-03 19:13 ` Mark Mielke
2003-02-03 19:24 ` Wesley W. Terpstra
2003-02-03 19:31 ` Gabriel Dos Reis
2003-02-03 19:37 ` Wesley W. Terpstra
2003-02-03 19:45 ` Phil Edwards
2003-02-03 20:08 ` Gabriel Dos Reis
2003-02-03 20:14 ` Phil Edwards
2003-02-03 20:15 ` Gabriel Dos Reis
2003-02-03 20:45 ` Andreas Schwab
2003-02-03 15:24 Bonzini
2003-02-03 16:45 ` Wesley W. Terpstra
2003-02-03 18:13 ` Alexandre Oliva
2003-02-03 18:17 ` Gabriel Dos Reis
2003-02-03 19:14 Wesley W. Terpstra
2003-02-03 19:16 Wesley W. Terpstra
2003-02-03 19:39 Chris Lattner
2003-02-03 19:47 ` Wesley W. Terpstra
2003-02-03 20:12 ` Gabriel Dos Reis
2003-02-03 21:25 Robert Dewar
2003-02-03 21:37 Robert Dewar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20030203090559.A20872@synopsys.com \
--to=jbuck@synopsys.com \
--cc=gcc@gcc.gnu.org \
--cc=terpstra@ito.tu-darmstadt.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).