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,7d3cb5920e882220 X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!feeder3.cambrium.nl!feeder1.cambrium.nl!feed.tweaknews.nl!62.216.30.27.MISMATCH!newsgate.cistron.nl!xs4all!news.tele.dk!news.tele.dk!small.news.tele.dk!lnewsinpeer00.lnd.ops.eu.uu.net!bnewsinpeer00.bru.ops.eu.uu.net!emea.uu.net!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Exceptions Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.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: <5947aa62-2547-4fbb-bc46-1111b4a0dcc9@x69g2000hsx.googlegroups.com> <475a8d6d$0$30677$4d3efbfe@news.sover.net> Date: Sat, 8 Dec 2007 15:01:02 +0100 Message-ID: <145gsya555jlt$.8mvve9nqja9n$.dlg@40tude.net> NNTP-Posting-Date: 08 Dec 2007 15:01:03 CET NNTP-Posting-Host: 864b75f7.newsspool4.arcor-online.net X-Trace: DXC=\HRS On Sat, 08 Dec 2007 07:26:21 -0500, Peter C. Chapin wrote: > The problem often quoted is that there are cases where an exception > looks like it could happen, but for reasons the compiler doesn't know > can't actually happen. As a simple example consider the code fragment > > if Has_Acceptable_Value(X) then > P1(X); > P2(X); > P3(X): > end if; > > Suppose P1 raises an exception if X is negative. Depending on what > Has_Acceptable_Value does, it is quite possible that can't happen in the > code above. If you specify exception contracts the way Java did, then > the programmer in the above case ends up having to handle an exception > that won't happen or claim to propagate and exception that won't get > propagated. Either option is undesirable. The problem here is not exception contracts but firstly lack of subtypes in C++. Ada has subtypes, so the code above could be rewritten [properly]: if X in Safe_For_P1 then declare Checked_X : Safe_For_P1 renames X; begin P1 (Checked_X); -- This does not raise exception The actual problem for Ada is that there is no syntax sugar for "if X in S then X indeed in S" (:-)) This is not about exceptions, we also do if Ptr /= null then Foo (Ptr.all); No way to assure that Ptr cannot be null in Ptr.all to require the compiler to drop checks. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de