comp.lang.ada
 help / color / mirror / Atom feed
From: ajaskey@gnn.com (Andy Askey)
Subject: Re: Exceptions:  Are they GOTOs?
Date: 1996/07/14
Date: 1996-07-14T00:00:00+00:00	[thread overview]
Message-ID: <4s9o6e$ro4@news-e2b.gnn.com> (raw)
In-Reply-To: brad.837052481@ss1


brad@cs.uwa.oz.au (Bradley Edelman) 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.

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

>I'd appreciate thoughts either way.

>Thanks, Brad

I have been writing Ada seriously for the past 3 years and have a few
opinions about exceptions:

1)  Exceptions are the best method of unexpected result handling that
I have used compared to other languages (the best but not perfect).
If a designer/coder develops code in small modular chunks, then there
is never any problem of determining execution flow in the event of an
exception.  Real time, mission critical software runs much better with
a language that has exception handling built in than a language such
as C where it is up to some coder to anticipate everything.

2) Exceptions do not work like GOTOs when used correctly.  The
internal mechanism is different and is much neater in many cases.  Too
much emphasis is placed on code with perfect structural integrity (no
GOTOs, EXITs, BREAKs, RETURNs, etc...)  If the code is written in
small modular blocks it is very easy to read.  Only my mentors, the
old FORTRAN hacks, can screw up the asthetic beauty of a 30 line
source module.

3)  Exceptions do work like GOTOs when used incorrectly.  For example:

  if x = 1 then
    raise The_Exception;
  else
    raise The_Other_Exception;
  end if;

God I hate code like this.  The coder should have just used GOTOs.  I
always spend hours trying to figure out some hidden anterior motive.
When I figure out it was some bored coder getting cute, it drives me
to the bottle.

4)  Exceptions can degrade performance if every couple of lines is
blocked and and exception handler added.  My ruler of thumb is that if
I really need a handler, I add it.  If it makes my life easier, I only
add it for debugging purposes.

I have only written "old" Ada.  If anything has changed with Ada95 as
far as exceptions are concerned, I would be very interested in hearing
about them.

--
May your karma be excellent for forgiving my spelling mishaps.

Andy Askey
ajaskey@gnn.com





  parent reply	other threads:[~1996-07-14  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 ` Robert A Duff
1996-07-11  0:00 ` Michel Gauthier
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-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-13  0:00 ` Robert Dewar
1996-07-14  0:00 ` Andy Askey [this message]
1996-07-14  0:00   ` Laurent Guerby
1996-07-15  0:00     ` Andy Askey
1996-07-15  0:00       ` Robert Dewar
1996-07-14  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