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 Path: border1.nntp.dca3.giganews.com!backlog3.nntp.dca3.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!feeder.erje.net!eu.feeder.erje.net!news.stack.nl!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: OT: A bit of Sudoku Date: Fri, 6 Jun 2014 09:51:47 +0200 Organization: cbb software GmbH Message-ID: <1l2x0kuk3kxqx$.1owim8xhlww7x.dlg@40tude.net> References: <5365d3f0-43cc-47ef-989c-d47992c84c9f@googlegroups.com> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: QTaafVZuunHujkJPndFR7g.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 X-Original-Bytes: 3168 Xref: number.nntp.dca.giganews.com comp.lang.ada:186756 Date: 2014-06-06T09:51:47+02:00 List-Id: On Thu, 5 Jun 2014 16:39:47 -0700 (PDT), Adam Beneschan wrote: > On Thursday, June 5, 2014 4:12:55 PM UTC-7, Robert A Duff wrote: > >> In any case, if you need to jump out of many layers of (recursive?) >> calls, an exception might well be the best way. Checking error >> codes at each level might be verbose and error prone. > > I don't like it. But if you do something like this, I'd suggest that this > use be limited to an exception that you declare inside a subprogram, so > that you raise and handle it only inside that subprogram or nested > subprograms. Exceptions is a part of the subprogram contract. > Otherwise, someone could look at a subprogram that is called in between, > and never guess that the subprogram might not complete normally (A calls > B, B calls C, C raises an exception that gets passed over B's head back to > A; a programmer trying to read B might not suspect that B may not complete > in a non-error situation.) In other words, keep such usages as localized > as possible. Rather, let Ada 2X formalize exception contracts and leave checking the contracts to the compiler. The scenario you described is the valid and very useful use case of exceptions. The reason is that, likely, C and B could not handle the state when the exception was raised and propagated because in order to be able to handle it, they must be redesigned completely. They must have the information hidden from them for very good reason, affect program states possibly unrelated to them etc. I.e. it would make the design tightly coupled and fragile. The idea of exception is postponing handling of some [exceptional] states up to a context where handling were possible, e.g. in A. That context can be and usually is totally unknown to the designer of the code raising the exception. > Another thing to keep in mind is that exceptions cause overhead. Or reduce overhead when used properly, e.g. while not End_Of_File (File) loop ... end loop; vs. loop ... end loop; exception when End_Error => ... -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de