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.6 required=5.0 tests=BAYES_20,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: ajaskey@gnn.com (Andy Askey) Subject: Re: Exceptions: Are they GOTOs? Date: 1996/07/14 Message-ID: <4s9o6e$ro4@news-e2b.gnn.com>#1/1 X-Deja-AN: 168274053 references: x-gnn-newsserver-posting-date: 14 Jul 1996 03:05:50 GMT organization: GNN newsgroups: comp.lang.ada Date: 1996-07-14T00:00:00+00:00 List-Id: 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