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!news.glorb.com!newscon02.news.prodigy.net!prodigy.net!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: Exceptions Date: Thu, 13 Dec 2007 08:40:34 -0500 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <5947aa62-2547-4fbb-bc46-1111b4a0dcc9@x69g2000hsx.googlegroups.com> <475c688f$0$17524$9b4e6d93@newsspool4.arcor-online.net> <4dae26fe-0c8a-46e1-9a33-43c18cf757ae@i3g2000hsf.googlegroups.com> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1197553236 26022 192.74.137.71 (13 Dec 2007 13:40:36 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Thu, 13 Dec 2007 13:40:36 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:aN7dzmRgUl1IO/fEMWQ4MvnFYdo= Xref: g2news1.google.com comp.lang.ada:18920 Date: 2007-12-13T08:40:34-05:00 List-Id: Maciej Sobczak writes: > On 11 Gru, 09:07, Stephen Leake > wrote: > >> For code I have control over, I agree with Bob, except I use a >> different exception; raise Programmer_Error if you've detected a bug. > > I understand that this way you want to signal something much more > severe than "mere" Constraint_Error or such. > The problem is that Program_Error can be shut up by some null handler > or it can be translated to some other exception and then lose its > original weight. The solution to "when others => null;" and the like is better education. Competent programmers need to know not to do that, except in rare cases, where a big fat comment is in order. (Unfortunately, the designers of Ada 83 made exactly this mistake for task bodies! And Ada 95 repeats it for interrupt handlers.) I don't consider Constraint_Error "mere", by the way. It almost always represents a bug. > Why not terminating the program right on the spot by simply: > > pragma Assert (False); > > ? That doesn't terminate the program on the spot. It raises Assertion_Failure. I consider all of these: pragma Assert (False); Assert (False); -- Assert is a user-defined procedure raise Program_Error; raise Bug; -- Bug is a user-defined exception used project-wide to be legitimate ways of reporting a self-detected bug. There ought to be a standard predefined procedure for stopping the program "on the spot". Since there isn't, you can import "exit". > (yes, there are compiler options to switch it off as well) Indeed, it's turned off by default in GNAT (which I don't much like). > Does anybody use this strategy in regular code? > I happen to use it in test units and I find it very appropriate there. > Any thoughts on using assertions, including Assert(False), in > production code? Nothing wrong with using assertions in production code. - Bob