comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Subject: Re: Get_Line problem (GNAT bug?)
Date: Thu, 07 Dec 2006 17:23:34 -0500
Date: 2006-12-07T17:23:34-05:00	[thread overview]
Message-ID: <wccodqftkex.fsf@shell01.TheWorld.com> (raw)
In-Reply-To: 7fm8le.pa5.ln@hunter.axlog.fr

Jean-Pierre Rosen <rosen@adalog.fr> writes:

> Maciej Sobczak a �crit :
>>> 3. As Adam has suggested, End_Error exception is the right design;
>> I don't find it to be "right". For me, exception is something that is
>> unexpected. An error, usually.
> I beg to differ. Otherwise, they would be called "errors" or "abnormal".
> An exception corresponds to an "exceptional" event, i.e. something that
> prevents usual processing, and forces you to an exceptional handling.

I basically agree with Jean-Pierre here.  I like to put it this way:
exceptions are for separating different parts of the software that have
different views of what's an "error" and/or what to do about it.

For example, extracting something from a container, when that
"something" does not exist (because the container is empty, or
the lookup fails, or whatever).  From the point of view of the container
package, this could be considered an "error".  From the point of view of
the client, it could be an error/bug, or it could be perfectly normal
and recoverable.  So the container raises an exception, and the client
gets to decide what to do about it (handle the exception and continue,
or write the client code so the exception won't happen, or ...).

>.. If
> you consider that normal processing (normally the body of a loop) is the
> rule, it is an exception to the rule.

Well, I'm not sure I agree with that.  I mean, if you're looping through
an array, you normally check against 'Last, via "while", or "exit when", 
of implicitly via "for I in X'Range...".  You don't (normally) let your
index go past the end, and then handle the Constraint_Error outside the
loop.

It seems like looping through a file ought be similar to looping through
an array, in this regard.

>...And EOF certainly matches this
> definition (as is an error, of course, but it is not the only case).
>
> Exceptions are a useful tool in the programmers tool box. The narrow
> view of exceptions as just a way to handle errors is a mistake that
> prevents elegant solutions to some problems, in my view, and I've been
> constantly fighting against that.

Agreed -- if one says "exceptions are only for errors", then one has to
define "error", and that's impossible, since "error" depends on the
point of view.

- Bob



  parent reply	other threads:[~2006-12-07 22:23 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-06 14:25 Get_Line problem (GNAT bug?) Maciej Sobczak
2006-12-06 18:06 ` Adam Beneschan
2006-12-06 20:34 ` Gautier
2006-12-06 21:47 ` Dmitry A. Kazakov
2006-12-06 23:40   ` Adam Beneschan
2006-12-07  0:02     ` Björn Persson
2006-12-07  1:09       ` Adam Beneschan
2006-12-07  1:28         ` Björn Persson
2006-12-07  5:00         ` Jeffrey R. Carter
2006-12-07  8:26   ` Maciej Sobczak
2006-12-07  9:21     ` Jean-Pierre Rosen
2006-12-07 13:35       ` Ludovic Brenta
2006-12-07 22:23       ` Robert A Duff [this message]
2006-12-07 10:22     ` Dmitry A. Kazakov
2006-12-07 14:51       ` Maciej Sobczak
2006-12-07 16:29         ` Dmitry A. Kazakov
2006-12-08  8:22           ` Maciej Sobczak
2006-12-07 22:50       ` Robert A Duff
2006-12-08  0:13         ` Randy Brukardt
2006-12-08  4:04         ` Larry Kilgallen
2006-12-08  9:11         ` Dmitry A. Kazakov
2006-12-07  9:14   ` Jean-Pierre Rosen
2006-12-07  3:34 ` Steve
2006-12-07 17:42   ` Adam Beneschan
2006-12-07 22:35     ` Robert A Duff
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox