This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: try, finally


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 ]
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]