comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: OT: A bit  of Sudoku
Date: Fri, 6 Jun 2014 09:51:47 +0200
Date: 2014-06-06T09:51:47+02:00	[thread overview]
Message-ID: <1l2x0kuk3kxqx$.1owim8xhlww7x.dlg@40tude.net> (raw)
In-Reply-To: c0760c4e-8809-4c04-b454-3cd5bdc98538@googlegroups.com

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


  reply	other threads:[~2014-06-06  7:51 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-05 17:49 OT: A bit of Sudoku Mike H
2014-06-05 18:30 ` Adam Beneschan
2014-06-05 19:00   ` J-P. Rosen
2014-06-05 19:18     ` Jeffrey Carter
2014-06-05 19:43       ` J-P. Rosen
2014-06-05 20:05     ` Mike H
2014-06-05 23:12     ` Robert A Duff
2014-06-05 23:39       ` Adam Beneschan
2014-06-06  7:51         ` Dmitry A. Kazakov [this message]
2014-06-06  9:21           ` Georg Bauhaus
2014-06-06 13:38             ` Dmitry A. Kazakov
2014-06-06 15:47           ` Adam Beneschan
2014-06-06 17:09             ` Dmitry A. Kazakov
2014-06-07  6:03             ` J-P. Rosen
2014-06-06 14:13         ` Brad Moore
2014-06-13  0:21     ` Shark8
2014-06-13  6:30       ` J-P. Rosen
2014-06-13 10:10       ` Mike H
2014-06-13 12:37         ` Dmitry A. Kazakov
2014-06-13 15:47         ` Shark8
2014-06-05 20:03   ` Mike H
2014-06-05 20:40     ` Adam Beneschan
2014-06-06  9:10       ` Stefan.Lucks
2014-06-06 10:59         ` Mike H
2014-06-06 16:06         ` Adam Beneschan
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox