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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no 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!news3.google.com!news2.volia.net!newsfeed01.sul.t-online.de!t-online.de!easynews.net!easynet-isham!easynet.net!151.189.20.20.MISMATCH!newsfeed.arcor.de!news.arcor.de!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Java exception model. Was: Re: Ada Quality and Style book discussion ("_Type" suffix) Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.14.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <1132227241.9036.44.camel@sonnenregen> <437c877e$1_1@glkas0286.greenlnk.net> Date: Fri, 18 Nov 2005 14:18:43 +0100 Message-ID: NNTP-Posting-Date: 18 Nov 2005 14:18:43 MET NNTP-Posting-Host: 5f583301.newsread4.arcor-online.net X-Trace: DXC=20BWeOiSHZh18V74W6`bol:ejgIfPPlddjW\KbG]kaMh1BZS;MmC65fWMRhSHTe0VaWRXZ37ga[7jn919Q4_`VjiB8=X\UUgbkd X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:6464 Date: 2005-11-18T14:18:43+01:00 List-Id: On Fri, 18 Nov 2005 11:48:46 GMT, Peter C. Chapin wrote: > 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. I can't tell for Java, but let consider Ada adopting a contract model of exceptions. Your reasoning above is flawed. If the designer of Outer knows that the exception X cannot propagate out of it then it should be: procedure Outer is begin if Some_Complicated_Check then begin Inner; exception when X => -- This is not a state, it is a bug raise Program_Error; end if; end if; end Outer; > 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 think it is a software design issue. When exceptions and exceptional states are considered as *valid* states, then there cannot be any good argument against contract model of exceptions. They belong to a *functional* part of the program. What is left, are the arguments like - it is too difficult to implement; there would be too big overhead; I don't know how to do it right - not much impressive. Alternatively you can say, OK, exceptions are exclusively for software bugs. But this is also a quite weak position, because if they are bugs, then why would you like to handle them? Bugs to be debugged! -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de