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,2a687662f09731bb X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!newsread.com!newsstand.newsread.com!POSTED.monger.newsread.com!not-for-mail From: "Peter C. Chapin" User-Agent: Mozilla Thunderbird 1.0.7 (Windows/20050923) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Java exception model. Was: Re: Ada Quality and Style book discussion ("_Type" suffix) References: <1132227241.9036.44.camel@sonnenregen> <437c877e$1_1@glkas0286.greenlnk.net> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: Date: Fri, 18 Nov 2005 11:48:46 GMT NNTP-Posting-Host: 216.114.167.40 X-Complaints-To: Abuse Role , We Care X-Trace: monger.newsread.com 1132314526 216.114.167.40 (Fri, 18 Nov 2005 06:48:46 EST) NNTP-Posting-Date: Fri, 18 Nov 2005 06:48:46 EST Organization: SoVerNet (sover.net) Xref: g2news1.google.com comp.lang.ada:6461 Date: 2005-11-18T11:48:46+00:00 List-Id: Brian May wrote: > With respect to his complaint on exception handling - I like the Java > model where every exception that can be raised by a function has to be > declared - that way you don't have to check for exceptions that don't > currently occur - and if the specifications change, the compiler can > generate an error to let you know that you may not have considered an > exception. The problem with Java's model is that it forces the programmer to deal in some way with exceptions that semantically can't happen. Consider procedure Outer is begin if Some_Complicated_Check then Inner; end if; end Outer; Suppose procedure Inner raises an exception under certain conditions yet can't do so in the code above because Inner is only executed when the complicated check succeeds. Assume that under those particular conditions, it will never fail. The Java exception model would require us to either handle an exception that will never occur, or declare that Outer might raise an exception that we know it will never raise. Such a declaration will force Outer's callers to also do something about this impossible exception as well, etc, and so forth. The example above is simplistic and contrived but it's my belief that in real programs this sort of issue comes up a lot. I agree with the quoted article, though, in that using exceptions properly is surprisingly tricky and that it does require the programmer to think about non-local issues. I think there are times when the old fashion method of returning error codes is probably better. However, a blanket prohibition against exceptions is probably an over reaction. Peter