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,7d3cb5920e882220 X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!eweka.nl!lightspeed.eweka.nl!195.114.231.69.MISMATCH!feeder.news-service.com!feeder.news-service.com!feeder1.cambrium.nl!feed.tweaknews.nl!193.141.40.65.MISMATCH!npeer.de.kpn-eurorings.net!npeer-ng1.kpn.DE!newsfeed.arcor.de!newsspool2.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Fri, 07 Dec 2007 11:21:11 +0100 From: Georg Bauhaus User-Agent: Thunderbird 2.0.0.9 (Windows/20071031) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Exceptions References: <5947aa62-2547-4fbb-bc46-1111b4a0dcc9@x69g2000hsx.googlegroups.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Message-ID: <47591e9b$0$16574$9b4e6d93@newsspool1.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 07 Dec 2007 11:21:15 CET NNTP-Posting-Host: 67d58acb.newsspool1.arcor-online.net X-Trace: DXC=4ZmkjliEMHdJ00P1S40fZgic==]BZ:afn4Fo<]lROoRa4nDHegD_]ReF@3j6n\E;@oA:ho7QcPOVcD8d_o:Q2]\lDbah06gEX:l X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:18759 Date: 2007-12-07T11:21:15+01:00 List-Id: Dmitry A. Kazakov wrote: > On Thu, 06 Dec 2007 15:24:44 -0600, tmoran@acm.org wrote: > >>> Is there any way to force programmers to catch exception that >>> your function throws? > >> Do you mean force them to write code like: >> begin >> y := func(x); >> exception >> when funcs_important_exception=>null; -- ignore unimportant exception >> end; > When "a way to force" reads "exceptions contract", then the answer is no, > there is no way, alas. > Nevertheless, the function can be declared in a package next to an exception declaration. This should, I think, alarm users of the package that the subprograms might raise an occurence. It should also point to who is responsible for catching. The exception's name can also be chosen to be more specific than Constraint_Error. Eiffel's way is to have names for pre- and post-conditions (etc.). The model is instructive, I think. feature {ANY} -- visible to any client func (x: INTEGER): INTEGER require even: x \\ 2 = 0 sizeable: x.abs > 2 do Result := raises_if_odd (x) -- o.K. Result := at_random(Result) -- might raise ensure -- Result is another integer provided some -- random number is good; -- otherwise, bad things might happen. end feature {NONE} -- fully private raises_if_odd(x: INTEGER): INTEGER -- assume x has been tested do Result := 42 // (x \\ 2 - 1) end g: RANDOM at_random(x: INTEGER): INTEGER -- try to produce another integer from `x` -- Forces a dangerous operation for this demo do g.forth Result := x // g.item -- deliberate danger! end