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=1.2 required=5.0 tests=BAYES_00,FROM_NUMERIC_TLD, INVALID_MSGID,REPLYTO_WITHOUT_TO_CC 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: steved@pacifier.com@199.2.117.163 (Steve Doiel) Subject: Re: Exceptions: Are they GOTOs? Date: 1996/07/12 Message-ID: <4s4gic$etl@news.pacifier.com>#1/1 X-Deja-AN: 167909732 references: organization: Pacifier BBS, Vancouver, Wa. ((360) 693-0325) reply-to: steved@pacifier.com (Steve Doiel) newsgroups: comp.lang.ada Date: 1996-07-12T00:00:00+00:00 List-Id: In , 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