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!news4.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!194.117.148.138.MISMATCH!pe2.news.blueyonder.co.uk!blueyonder!news-peer!btnet!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.arcor.de!newsspool2.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> <145gsya555jlt$.8mvve9nqja9n$.dlg@40tude.net> <475adbe8$0$30689$4d3efbfe@news.sover.net> Date: Sun, 9 Dec 2007 11:06:42 +0100 Message-ID: <1qbsb1u76vyrk.3n8oov6aevw3$.dlg@40tude.net> NNTP-Posting-Date: 09 Dec 2007 11:06:44 CET NNTP-Posting-Host: 510a2dc9.newsspool3.arcor-online.net X-Trace: DXC=FlE3hOM\RS>^cW`WBF>WQ`PGja[TFeF09D>Q3ifj=`> X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:18798 Date: 2007-12-09T11:06:44+01:00 List-Id: On Sat, 08 Dec 2007 13:01:13 -0500, Peter C. Chapin wrote: > Dmitry A. Kazakov wrote: > >> 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 > > Here is my example again: > > if Has_Acceptable_Value(X) then > P1(X); > end if; > > What if Has_Acceptable_Value(X) returns true if X is prime... or a > positive power of two? I don't believe you can use Ada subtypes to > express conditions like that---or indeed many other possibilities. Yes, but it that case very design of P1 is in question. Why the set of values where P1 is defined does not constitute some semantically integral body (like a subtype)? P1 is an operation of what? Maybe I would not use exceptions in P1, or else mark the caller of P1 as propagating the exception of P1. > However, since primes (or positive powers of two, etc) aren't negative, > my earlier point is still valid. The above code won't raise the > exception in P1 (assume P1 only raises for negative arguments) so > handling it or claiming to propagate it is a waste of resources and > misleading. On the contrary, if I decided to use an exception in P1, then I would see it as an advantage that the language would force me to put a handler around P1, because semantic relation between Has_Acceptable_Value and P1 is not obvious since there is no subtype. Later me or another maintainer of the code will certainly forget about any relation between them and mistakenly remove if Has_Acceptable_Value. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de