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,699cc914522aa7c4 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news2.google.com!news.germany.com!news.tu-darmstadt.de!newsfeed.hanau.net!news-fra1.dfn.de!newsfeed.ision.net!newsfeed2.easynews.net!ision!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Structured exception information 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: <1168885771.30643.20.camel@localhost> <1168891576.30643.39.camel@localhost> <5NKdnTv2UZfVZTbYnZ2dnUVZ_vipnZ2d@megapath.net> <38z8yk9z1uxn$.1r6qpevwu2i7c.dlg@40tude.net> Date: Tue, 16 Jan 2007 19:31:03 +0100 Message-ID: NNTP-Posting-Date: 16 Jan 2007 19:30:58 CET NNTP-Posting-Host: adce3839.newsspool2.arcor-online.net X-Trace: DXC=6;l@2@<^[7\1`E>oC;JXEZA9EHlD;3YcR4Fo<]lROoRQFl8W>\BH3YR>:XYjFTULFPDNcfSJ;bb[UIRnRBaCd On Tue, 16 Jan 2007 17:50:46 GMT, Jeffrey Carter wrote: > Dmitry A. Kazakov wrote: >> >> procedure Foo raises Foo_Error; -- Compile error! > > Generally, subprograms should raise exceptions because of precondition > violations. If the preconditions are met, the subprogram should not > raise an exception (barring things that are beyond the developer's > control, such as running out of memory). So it would be better to > associate a subprogram with a list of preconditions with the exception > raised if each is violated: > > function Arccoth (Coth : Real) return Real > when abs Coth < 1.0 raise Invalid_Coth; > > procedure Time_Limited (X : in Integer) > when X = 0 raise Zero_X and > when Ada.Calendar.Clock >= > Ada.Calendar.Time_Of (Year => 2010, > Month => 1, > Day => 1, > Seconds => 0.0) > raise Too_Late; Totally disagree. A precondition violation is not an exceptional state, it is a bug. Bugs fundamentally cannot be handled within the same program. This "exception" should propagate in the visual debugger and further into the head of the code maintainer, If you want. The difference becomes obvious if you consider that there might well be valid program states corresponding to the end of a file. But there cannot be any valid and consistent state in which there would exist x such that cosh(x)<1. Therefore their handling strategies are quite different as well. Bugs propagating exceptions is the worst debugging nightmare. A precondition violation shall stop immediately to prevent further harm and to make a inspection possible. Exceptions are just a method of flow control. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de