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!news2.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 09:44:42 -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> <9f16235c-260a-460b-873c-2183c154cc0c@e25g2000prg.googlegroups.com> NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls6.std.com 1197557086 18836 192.74.137.71 (13 Dec 2007 14:44:46 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Thu, 13 Dec 2007 14:44:46 +0000 (UTC) User-Agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.3 (irix) Cancel-Lock: sha1:HeohAjossi6sRW78doJU2ks8jFY= Xref: g2news1.google.com comp.lang.ada:18923 Date: 2007-12-13T09:44:42-05:00 List-Id: Maciej Sobczak writes: > On 13 Gru, 14:40, Robert A Duff wrote: > >> The solution to "when others => null;" and the like is better >> education. > > Isn't it also a solution for all the presumed problems of C/C++? > Sorry, could not resist. ;-) I see the smiley, but... Here's a serious reply anyway: A language design should not try to prevent people from doing bad things. It should try to prevent people from doing bad things BY ACCIDENT. The Java programmers who have been mentioned several times in this thread -- the ones who evilly stick in do-nothing handlers -- are doing so on purpose. Any attempt to fix that problem via language design will backfire. Fixing it via education OTOH has a good chance of success. Forgetting to handle an exception, however, is an accident. A language design can help there, but education will not. >> I don't consider Constraint_Error "mere", by the way. >> It almost always represents a bug. > > What about a situation when a user entered an input data that was > outside of legal (and documented) range? Or that caused our of range > value further down the pipe? > This is not necessarily a bug, just an indication that the value is > out of range. The exception can help to come back to the input loop > and repeat the user scenario, abandoning all the state that was > created in the meanime. This way the program does not enter into any > abnormal state. Well, you can't refute an "almost always" statement by giving a counterexample. ;-) Yes, in the situation you mention, it's reasonable to say: when Constraint_Error => null; -- loop back and ask user again I've got no problem with that, so long as there's a good comment. It should not be "when others" in this case, either. >> There ought to be a standard predefined procedure for stopping the >> program "on the spot". Since there isn't, you can import "exit". > > I was wandering whether there is any standard mechanism for this. You can abort the environment task. But I'm not sure what that will do in a multi-threaded, multi-language program -- depends on the implementation. Anyway, it's an ugly trick. I'd rather be able to portably say "Kill_Program;" or "Kill_Program(exit_code);" or something like that. Note that you need to think carefully about whether you want finalizers to run. - Bob