comp.lang.ada
 help / color / mirror / Atom feed
From: "Marin David Condic" <marin.condic.auntie.spam@pacemicro.com>
Subject: Re: RISC
Date: Mon, 19 Mar 2001 12:02:59 -0500
Date: 2001-03-19T17:03:18+00:00	[thread overview]
Message-ID: <995e4m$n90$1@nh.pace.co.uk> (raw)
In-Reply-To: vIYs6.6150$227.669029@newsread2.prod.itd.earthlink.net

It isn't an efficiency issue. Its more of a "design philosophy" issue. If
you are working with systems that have a really high reliability
requirement, you'll get various arguments for and against using exceptions.
(Hard to mathematically "prove" the code, vs "that's what exceptions are
for!" arguments.)

Exceptions can be viewed as a sort of "limited/controlled goto" - and as
such they can pose hazards to good software design. For example, the Text_IO
package will raise an exception if you try to read past the end of a file
because it has no way of knowing what you are attempting to do or why. It
just knows you asked it to do the impossible so it properly throws up its
hands, curses you in exasperation and raises an exception. However, *your*
code ought to know what it is doing with the file and should properly be
checking for End_Of_File as an anticipated condition. You might protect
yourself by trapping any EOF exceptions because you may have made a
programming error and in some corner case you attempt to read past the end
of the file.

Your code should be raising exceptions in similar circumstances - when it
becomes clear that some condition has occurred that is beyond the
understanding and the *responsibility* of the module in which it is raised.
A good example is a function that is undefined for some combination of
parameters. The function in effect says "I have no idea why you sent me this
combination of numbers and there really isn't anyting intelligent I can do
with them to fix the problem and let you press on, so I'm going to raise an
exception that you cannot ignore so you are aware that you probably made a
mistake." The calling code should be trapping exceptions (or not) as a means
of catching unexpected conditions - but not as a normal transfer of control
mechanism. (You would consider it "bad form" to terminate your programs by
dividing by zero, wouldn't you? Same concept here.)

And remember that raising & handling exceptions may or may not be done
depending on the nature of the system. You have to consider this in the
requirements/design phases of the system & plan accordingly. (id est, take a
decision about what exception philosophy should be followed for *this*
application.)

MDC
--
Marin David Condic
Senior Software Engineer
Pace Micro Technology Americas    www.pacemicro.com
Enabling the digital revolution
e-Mail:    marin.condic@pacemicro.com
Web:      http://www.mcondic.com/



"Charles Hixson" <charleshixsn@earthlink.net> wrote in message
news:vIYs6.6150$227.669029@newsread2.prod.itd.earthlink.net...
> Robert A Duff wrote:
>
> > "Marin David Condic" <marin.condic.auntie.spam@pacemicro.com> writes:
> >
> >> Its hard to come up with absolute rules since it often requires
> >> subjective, artistic judgements. Just keep in mind that the intention
is
> >> to have a mechanism that deals with *errors* - not anticipated
conditions
> >> that can be accommodated with some sort of "normal" processing.
> >
> >....
> > Another way to look at it is that the point of exceptions is to separate
> > the code that *detects* errors from the code that *handles* those
> > situations.  If the code that detects something knows what to do about
> > it, then exceptions aren't necessary -- that code can just have an 'if'
> > statement that checks the condition, and handles the situation in the
> > 'then' part.
> >
> > - Bob
> >
>
> Is the problem that exceptions are expensive, or that exceptions violate
> localization?  Or something else?
>
> E.g.:  Should EOF detection be done with an exception?  It's usuaual, but
> expected.  I think of encountering an EOF and an unusual condition, and
> it's nice to be able to automatically check for it whenever a read happens
> without explicitly calling on an eof() function.
>
> Java rather expects that procedures will throw exceptions.  I don't know
> C++ well enough to comment.  Python seems to believe that exceptions are
> quite reasonable.  Eiffel thinks that exceptions should be handled within
> the same routine that defines them. Etc.  I think that this is a language
> specific issue.
>
> My impression was that Ada exceptions were intended to handle unusual
cases
> (exceptional cases).  That they were slightly more expensive to raise than
> a local branch would be, but that they were slightly cheaper if no
> exceptional case was detected.  And that they should be handled as close
to
> the routine that raised them as possible.  Preferably within the routine.
> But I would hardly call myself an expert at Ada.
>
>





  parent reply	other threads:[~2001-03-19 17:02 UTC|newest]

Thread overview: 82+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-03-14 20:23 RISC chris.danx
2001-03-14 21:57 ` RISC Tucker Taft
2001-03-14 22:36   ` RISC chris.danx
2001-03-14 23:03     ` RISC Fraser Wilson
2001-03-15  1:30       ` RISC Corey Ashford
2001-03-15  9:19       ` RISC chris.danx
2001-03-15 12:37 ` RISC chris.danx
2001-03-15 13:03   ` RISC Tarjei T. Jensen
2001-03-15 18:29     ` RISC Robert A Duff
2001-03-15 14:40   ` RISC Ted Dennison
2001-03-15 14:49     ` RISC Robert A Duff
2001-03-15 17:37       ` RISC Marin David Condic
2001-03-15 18:28         ` RISC Robert A Duff
2001-03-15 19:16           ` RISC Marin David Condic
2001-03-16  8:44             ` RISC Martin Dowie
2001-03-16 14:40               ` RISC Marin David Condic
2001-03-20 10:17                 ` RISC Martin Dowie
2001-03-20 14:34                   ` RISC Marin David Condic
2001-03-20 15:45                     ` RISC Ted Dennison
2001-03-20 16:39                       ` RISC Robert A Duff
2001-03-20 18:10                       ` RISC Martin Dowie
2001-03-20 18:56                         ` RISC Ted Dennison
2001-03-22  9:16                       ` RISC - largish (code listed) Martin Dowie
2001-03-22  9:34                         ` Martin Dowie
2001-03-20 18:09                     ` RISC Martin Dowie
2001-03-20 20:00                       ` RISC Marin David Condic
2001-03-20 22:30                         ` RISC Robert A Duff
2001-03-20 22:48                           ` RISC Ted Dennison
2001-03-20 23:10                           ` RISC Marin David Condic
2001-03-21  0:18                             ` RISC Robert A Duff
2001-03-21 14:31                               ` RISC Marin David Condic
2001-03-21 16:47                                 ` RISC Ted Dennison
2001-03-21 17:36                                   ` RISC Marin David Condic
2001-03-16 15:09             ` RISC Tucker Taft
2001-03-16 17:10               ` RISC Robert A Duff
2001-03-16 19:02                 ` RISC Marin David Condic
2001-03-16 20:58                   ` RISC Robert A Duff
2001-03-19 16:17                     ` RISC Marin David Condic
2001-03-19 16:45                       ` RISC Florian Weimer
2001-03-19 17:14                         ` RISC Marin David Condic
2001-03-19 17:33                           ` RISC Florian Weimer
2001-03-21  5:57                           ` RISC Lao Xiao Hai
2001-03-16 22:19                   ` RISC Ted Dennison
2001-03-16 19:13                 ` RISC Laurent Guerby
2001-03-16 20:30                   ` RISC Robert A Duff
2001-03-16 20:51                 ` RISC Ole-Hjalmar Kristensen
2001-03-16 18:33               ` RISC Marin David Condic
2001-03-16 20:45                 ` RISC Robert A Duff
2001-03-17  1:13                   ` RISC Randy Brukardt
2001-03-19 16:34                   ` RISC Marin David Condic
2001-03-19 17:49                     ` RISC Robert A Duff
2001-03-16 20:08 ` RISC chris.danx
2001-03-16 20:31   ` RISC Marin David Condic
2001-03-17 21:51     ` RISC Robert A Duff
2001-03-18  6:37       ` RISC Charles Hixson
2001-03-19 15:42         ` RISC Robert A Duff
2001-03-19 17:02         ` Marin David Condic [this message]
2001-03-19 17:45           ` RISC Robert A Duff
2001-03-19 18:48             ` RISC Marin David Condic
2001-03-19 16:45       ` RISC Marin David Condic
2001-03-16 22:27 ` RISC chris.danx
2001-03-17  2:49   ` RISC Jeffrey Carter
2001-03-19  9:43   ` RISC Martin Dowie
2001-03-19 11:06     ` RISC chris.danx
2001-03-28 22:24     ` RISC chris.danx
2001-03-29  0:52       ` RISC Corey Ashford
2001-03-29 12:42       ` RISC John English
2001-03-22 20:11 ` RISC chris.danx
2001-03-22 20:51   ` RISC Marin David Condic
2001-03-22 21:02   ` RISC tmoran
2001-03-22 21:18     ` RISC chris.danx
2001-03-22 21:45   ` RISC Britt Snodgrass
2001-03-22 22:43     ` RISC chris.danx
2001-03-28 11:37   ` RISC chris.danx
  -- strict thread matches above, loose matches on Subject: below --
2001-03-16 23:25 RISC Beard, Frank
2001-03-17 11:39 ` RISC chris.danx
2001-03-29  3:12 RISC Beard, Frank
2001-03-29  7:28 ` RISC Martin Dowie
2001-03-29 12:38 ` RISC chris.danx
2001-03-29 19:07 ` RISC Chad R. Meiners
2001-03-29 17:52 RISC Beard, Frank
2001-03-30 17:31 RISC Kent Paul Dolan
replies disabled

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