comp.lang.ada
 help / color / mirror / Atom feed
From: steved@pacifier.com@199.2.117.163  (Steve Doiel)
Subject: Re: Exceptions:  Are they GOTOs?
Date: 1996/07/12
Date: 1996-07-12T00:00:00+00:00	[thread overview]
Message-ID: <4s4gic$etl@news.pacifier.com> (raw)
In-Reply-To: brad.837052481@ss1


In <brad.837052481@ss1>, brad@cs.uwa.oz.au (Bradley Edelman) writes:
>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

In my experience I have seen programs that don't have exceptions that bomb
mysteriously when something goes wrong.  It is common practice in C to
call calloc and not check the result, just use the allocated memory (I expect
a flame for that, but I have seen this in "professional" programs).

On my current project, I implemented exception handlers in C using setjmp and
longjmp and encapsulate all "calloc's" within exception handlers.  This will
not keep the program from bombing, but at least I'll know why so I can fix the
problem.

I've read a lot of "rules" of programming: "goto's are bad", "avoid tasking
where possible".  But what I've learned by experience is that these "rules"
are really guidelines.  What's it's really all about is making code that may
be easily understood and therefore easily maintained (which is why Ada is
usually a better choice than 'C').

In trying to read code, if every possible error condition is checked in line
it may involve nested if's that are hard to read.  When exceptions are used
the checks can be made directly where the errors might occur within reusable
components, and the normal flow of code may look very simple.

My opinion:
When code is easier to read is safer and easier to maintain.
Exceptions can make code easier to read.
Therefore exceptions are not bad.

(Of course you can misuse exceptions like anything else)

Steve Doiel





  parent reply	other threads:[~1996-07-12  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
1996-07-12  0:00 ` steved [this message]
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