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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,ec21c3c7cdc7ff3e X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.megapath.net!news.megapath.net.POSTED!not-for-mail NNTP-Posting-Date: Mon, 20 Mar 2006 17:57:41 -0600 From: "Randy Brukardt" Newsgroups: comp.lang.ada References: <1142279908.327131.230200@j52g2000cwj.googlegroups.com> <41LSf.4126$TK2.1805@trnddc07> <7LOSf.34253$oL.29742@attbi_s71> Subject: Re: Handling invalid objects Date: Mon, 20 Mar 2006 17:57:47 -0600 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 Message-ID: NNTP-Posting-Host: 64.32.209.38 X-Trace: sv3-KhF5UNmkmFinRzAue0/oGiSr0fJ5sctxiVgZ+zABCdwDzMZ1IlpFl62ZhjZ9Jc3GElxbPPL+AOPPbrN!1vGfj/C1wJGRZN4Yw2saBQi8bTuj9nxq7WivpiV2PsZP54wPTVS16OOMgO1w0vhLljb4ASfCveTE!3mEujENVI2SIRA== X-Complaints-To: abuse@megapath.net X-DMCA-Complaints-To: abuse@megapath.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.32 Xref: g2news1.google.com comp.lang.ada:3509 Date: 2006-03-20T17:57:47-06:00 List-Id: "Justin Gombos" wrote in message news:niWSf.1278$I7.339@trnddc03... ... > I recall working to a coding standard that barred exception raising > when other mechanisms for error detection are possible. It > effectively banned exception raising altogether because you can always > send an error notice by other means. Exceptions are synonymous with > goto statements, with the additional effect of creating an > unpredictable state so I didn't challenge the rule. You should have; such a coding standard is brain-damaged. Unless there is a total ban on exceptions (as in SPARK -- and I disagree with SPARK on that), there is no good reason to avoid exceptions. It's important that they not be overused - especially in situations where it is normal and expected that the failure occur (such as in a Find routine). But it's silly to avoid them, even in rare but expected situations (such as end-of-file). Indeed, my view is exceptions and exception handling were one of the primary leaps forward for Ada over its sibling languages Pascal and Modula. Using exceptions in cases like this allow the writer of the routine to be sure that the error is not ignored, causing cascading problems later - and ensure that the error is localized if it is made. > Exception raising and handling is often viewed as writing code that > will never execute. Predefined exceptions must be handled when there > is an expectation they will be raised, but their usefullness stops > there. Beyond that, it's like writing erroneous code on purpose. Yikes! I hope you never work for me! I think returning an invalid value on purpose is like writing erroneous code on purpose. That's because you're trusting the caller to do the right thing and check something; if you look at the typical C code, it's pretty clear that doesn't happen much. Exceptions let you put the error recovery code where it makes the most sense -- which is usually quite a long ways from wherever the error occurred. And it doesn't require any trust from the user of your abstraction. (Note that this still applies even when you are your own consumer - no one is perfect enough to remember to do things not indicated in the specification.) Randy.