comp.lang.ada
 help / color / mirror / Atom feed
From: bobduff@world.std.com (Robert A Duff)
Subject: Re: Exceptions:  Are they GOTOs?
Date: 1996/07/11
Date: 1996-07-11T00:00:00+00:00	[thread overview]
Message-ID: <DuDx6v.JMK@world.std.com> (raw)
In-Reply-To: brad.837052481@ss1


In article <brad.837052481@ss1>, Bradley Edelman <brad@cs.uwa.oz.au> wrote:
>What do people think about exception handling?  I believe it to be a major
>strength of Ada but there is a school of thought that exceptions are just
>GOTO statements and should be avoided accordingly.

Exceptions ARE like gotos -- only worse.  For a goto, you can know where
it's going by reading the code, and for a label, you can know how you're
going to get there by reading the code (assuming you don't have a LOT of
gotos going to the same label).  Furthermore, gotos are always local to
a given program unit.  Exceptions, on the other hand, are dynamic, so
you can't necessarily tell match "raise" with "handler" by reading the
code, and furthermore, they're much more global.

But that doesn't mean exception handlers are evil.  They're a powerful
(and therefore dangerous) tool, and should be used accordingly.

The school of thought you mention above is sort of silly, IMHO.  Some
people seem to use the word "goto" as a synonym for "evil", and avoid
actually *thinking* about if and when a goto, or a goto-like feature
such as exceptions, is appropriate.

Task swiching is vaguely like a goto, too, but that doesn't mean tasks
are evil.

>I think raising an exception is a neater way of handling an error than, say,
>returning an error code or status.

I strongly agree.

- Bob

P.S. The comments above are about Ada gotos.  There are languages where
you can goto a run-time-determined label value, and there are languages
where you can goto an outer procedure.  Raising an exception is
essentially the same thing as doing a goto to an outer scope, with the
label name (i.e. exception handler) being dynamically scoped.




  parent reply	other threads:[~1996-07-11  0:00 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-07-11  0:00 Exceptions: Are they GOTOs? Bradley Edelman
1996-07-11  0:00 ` Michel Gauthier
1996-07-11  0:00 ` Robert A Duff [this message]
1996-07-12  0:00 ` steved
1996-07-13  0:00   ` Michael Feldman
1996-07-16  0:00   ` Robert I. Eachus
1996-07-19  0:00     ` Michel Gauthier
1996-07-18  0:00   ` Robert Dunn
1996-07-18  0:00     ` Robert Dewar
1996-07-19  0:00       ` Larry J. Elmore
1996-07-20  0:00         ` Andy Askey
1996-07-12  0:00 ` Spasmo
1996-07-12  0:00   ` David Morton
1996-07-14  0:00   ` Robert Dewar
1996-07-17  0:00     ` Spasmo
1996-07-18  0:00       ` Walter B. Hollman Sr.
1996-07-20  0:00         ` Robert Dewar
1996-07-13  0:00 ` Robert Dewar
1996-07-14  0:00 ` Andy Askey
1996-07-14  0:00   ` Robert Dewar
1996-07-14  0:00   ` Laurent Guerby
1996-07-15  0:00     ` Andy Askey
1996-07-15  0:00       ` Robert Dewar
1996-07-15  0:00 ` OS2 User
1996-07-16  0:00 ` Michel Gauthier
1996-07-17  0:00 ` Michel Gauthier
replies disabled

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