public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: me22 <me22.ca@gmail.com>
To: gcc-help@gcc.gnu.org
Subject: Re: try, finally
Date: Fri, 21 Mar 2008 02:37:00 -0000	[thread overview]
Message-ID: <fa28b9250803201936k53dc0a97v4df3999d7d25d51a@mail.gmail.com> (raw)
In-Reply-To: <c09049bf0803201910h3eaeb34fwd5e00dc2a35efd6f@mail.gmail.com>

On Thu, Mar 20, 2008 at 10:10 PM, Jason Cipriani
<jason.cipriani@gmail.com> wrote:
> On Thu, Mar 20, 2008 at 8:23 AM, John Love-Jensen <eljay@adobe.com> wrote:
>  >  In my projects, throwing an exception mean "the application is about to
>  >  terminate."
>  >
>  >  That's using the exception mechanism at the extreme of conservative
>  >  programming with exceptions.
>  >
>  >  Assuming you use exceptions with less draconian policy, the exception
>  >  mechanism is not for using as normal flow control.  It really means an
>  >  exceptional situation, outside of the normal flow control.
>  >
>  >  For normal flow control -- such as handling predictable, common error
>  >  conditions -- you should use return codes.
>
>  It seems that the root of any disagreement is what kinds of errors
>  we'd prefer to represent with exceptions. You and Ted would use them
>  for rare, fatal error conditions, similar in spirit to machine
>  exceptions such as access violations and invalid instructions. I would
>  use them for more common errors such as invalid user input, missing
>  files, network errors, etc. I have a hunch nobody is going to be
>  having a change of heart any time soon. :-) One thing that I have
>  often noticed, incidentally, is that the longer a programmer has been
>  programming before C++, the more they prefer error codes to
>  exceptions.
>

Personally, I think that if something can't happen, like a divide by
zero, is a case for an assert, not an exception.  Leave them in the
release if you want, but better, fix them!

I prefer using exceptions for things that you'd rather never happened,
and if everything does perfectly, never will happen.  (Which also
means that their performance doesn't matter.)  Especially when those
are the kinds of things that can rarely be handled locally.  I like
having a fairly clean code path.

Also, exceptions thrown in constructors mean tighter invariants that
you just can't get with return codes.  2-phase construction is evil.

> [snip exceptionally long post that I didn't actually read, sorry :P ]
>

  reply	other threads:[~2008-03-21  2:37 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-19 16:13 Jason Cipriani
2008-03-19 16:14 ` Jason Cipriani
2008-03-19 17:02   ` Tim Prince
2008-03-19 16:37 ` Brian Dessent
2008-03-19 17:31 ` Ted Byers
2008-03-19 17:37 ` me22
2008-03-19 19:09   ` Jason Cipriani
2008-03-19 19:09     ` me22
2008-03-20  5:50       ` Jason Cipriani
2008-03-20 13:30       ` Noel Yap
2008-03-21  2:27         ` Jason Cipriani
2008-03-19 21:04     ` Ted Byers
2008-03-20  6:28       ` Jason Cipriani
2008-03-20 12:24         ` John Love-Jensen
2008-03-21  2:11           ` Jason Cipriani
2008-03-21  2:37             ` me22 [this message]
2008-03-21  2:45               ` Jason Cipriani
2008-03-21 15:24             ` Noel Yap
2008-03-21 22:50             ` Brian Dessent
2008-03-21 23:14               ` Noel Yap
2008-03-20 14:50         ` Ted Byers
2008-03-21  2:26           ` Jason Cipriani
2008-03-25 22:28 ` Ian Lance Taylor

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=fa28b9250803201936k53dc0a97v4df3999d7d25d51a@mail.gmail.com \
    --to=me22.ca@gmail.com \
    --cc=gcc-help@gcc.gnu.org \
    /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).