try, finally

Noel Yap noel.yap@gmail.com
Fri Mar 21 15:24:00 GMT 2008


On Thu, Mar 20, 2008 at 7:10 PM, Jason Cipriani
<jason.cipriani@gmail.com> wrote:
>  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 would use them for network errors.  Depending upon why files may be
missing, I may or may not use them for that purpose.  I would
definitely not use them for invalid user input.

I suppose where I would draw the line is whether or not the system has
control over the inputs in question.  For example, if a file is
expected to exist because another system or a user is supposed to
create the file, exceptions shouldn't be used.

I will say, though, that this is how I use exceptions in C++.  I'm
much more lax with exception usage in languages like Python and
possibly Java (I don't have that much experience with Java, but I did
use exceptions for flow control in order to implement an ISO-8601
parser whose grammar seemed to require some lookahead, but I may just
have lacked the skills to eliminate this (mis)use of exceptions).

Noel



More information about the Gcc-help mailing list