From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.1 required=5.0 tests=BAYES_05,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,bc243f3bb85ffa4f X-Google-Attributes: gid103376,public From: bobduff@world.std.com (Robert A Duff) Subject: Re: Exceptions: Are they GOTOs? Date: 1996/07/11 Message-ID: #1/1 X-Deja-AN: 167813068 references: organization: The World Public Access UNIX, Brookline, MA newsgroups: comp.lang.ada Date: 1996-07-11T00:00:00+00:00 List-Id: In article , 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. 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.