comp.lang.ada
 help / color / mirror / Atom feed
From: Fionn Mac Cumhaill <invisible@hiding.from.spam>
Subject: Re: Exceptions and out procedure arguments (using GNAT GPL)
Date: Wed, 20 Jun 2007 15:15:49 GMT
Date: 2007-06-20T15:15:49+00:00	[thread overview]
Message-ID: <h5gi735mb5hvoue53okqjqkkhimgtqfsci@4ax.com> (raw)
In-Reply-To: 1182266486.650797.262430@a26g2000pre.googlegroups.com

On Tue, 19 Jun 2007 08:21:26 -0700, Adam Beneschan <adam@irvine.com>
wrote:

>On Jun 19, 12:34 am, Maciej Sobczak <see.my.homep...@gmail.com> wrote:
>> On 19 Cze, 07:23, Fionn Mac Cumhaill <invisi...@hiding.from.spam>
>> wrote:
>>
>> > I eliminated the problem by modifying the offending procedure to not
>> > raise exceptions. It now returns a status code in an additional out
>> > argument.
>>
>> You might also introduce a temporary variable in the procedure to keep
>> the "candidate" result and copy it into the relevant out parameter
>> just before leaving the procedure (on the successful path).
>> This would be better than changing the interface and error handling
>> policy, which is very intrusive.
>
>But it might be the correct design anyway.  My gut feeling is that, in
>the abstract, a subprogram should either produce a result *or*
>(perhaps) raise an exception, but not both; in general, if your
>definition of a subprogram is that, under certain conditions, the
>subprogram will raise an exception AND the caller can expect a certain
>value to be returned (whether in an OUT parameter or an IN OUT or a
>global or in something pointed to by an access parameter or whatever)
>even though an exception is raised, the design is wrong.  It's better
>to use an OUT status code of some sort in that case.  Sorry if I'm not
>explaining this well---I don't always know what the common terminology
>is for the things I'm thinking.  Also, I'm not saying that this
>necessarily applies to Fionn's program.
>
>                     -- Adam
>

The design needed to change in any case. The original Query was a
function, not a procedure. It returned a handle to storage allocated
to hold information about the result set returned by the query. That
storage was allocated before the query was made. If no rows were
returned, the exception was raised and the handle was lost. Given the
design of the package, it might well have been possible to retrieve
the handle, but that would have required producing a new function or
procedure to find it. It is best not to lose it.

With the design as I now have it, a loop to process looks like this
pseudocode:

Open a Query, return handle to result set

while rows remain, process rows

Close the query and deallocate storage designated by the handle.

This is the simple and obvious way to do it, and works as expected
even when the number of rows returned by the query is 0. It requires
minimal revision to the original code to achieve this goal.




  parent reply	other threads:[~2007-06-20 15:15 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-16  1:05 Exceptions and out procedure arguments (using GNAT GPL) Fionn Mac Cumhaill
2007-06-16  1:53 ` Anh Vo
2007-06-16  2:50 ` Brian May
2007-06-16  3:08 ` Randy Brukardt
2007-06-16  6:55 ` Dmitry A. Kazakov
2007-06-18 15:44 ` Adam Beneschan
2007-06-19  5:23   ` Fionn Mac Cumhaill
2007-06-19  7:34     ` Maciej Sobczak
2007-06-19 15:21       ` Adam Beneschan
2007-06-19 20:07         ` Dmitry A. Kazakov
2007-06-19 21:20           ` Adam Beneschan
2007-06-20  6:16             ` Georg Bauhaus
2007-06-20  8:01             ` Dmitry A. Kazakov
2007-06-20  8:45               ` Georg Bauhaus
2007-06-20  9:29                 ` Dmitry A. Kazakov
2007-06-20  6:21           ` Georg Bauhaus
2007-06-20  8:02             ` Dmitry A. Kazakov
2007-06-20  8:46               ` Georg Bauhaus
2007-06-20  9:29                 ` Dmitry A. Kazakov
2007-06-20 10:13                   ` Georg Bauhaus
2007-06-20 12:58                     ` Dmitry A. Kazakov
2007-06-20 14:16                       ` Georg Bauhaus
2007-06-20 18:22                         ` Dmitry A. Kazakov
2007-06-20 19:16                           ` Georg Bauhaus
2007-06-20 20:40                             ` Dmitry A. Kazakov
2007-06-21  9:52                               ` Georg Bauhaus
2007-06-21 13:48                                 ` Dmitry A. Kazakov
2007-06-22 18:15                                   ` Georg Bauhaus
2007-06-22 19:45                                     ` Dmitry A. Kazakov
2007-06-20 15:15         ` Fionn Mac Cumhaill [this message]
2007-06-19 21:40     ` Randy Brukardt
replies disabled

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