comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: Code flow control
Date: Fri, 15 Oct 2021 17:51:41 -0500	[thread overview]
Message-ID: <skd0lu$ik$1@franka.jacob-sparre.dk> (raw)
In-Reply-To: 23031592-5a56-4d56-bda7-34877588802dn@googlegroups.com

"Kevin Chadwick" <kevc3no4@gmail.com> wrote in message 
news:23031592-5a56-4d56-bda7-34877588802dn@googlegroups.com...
On Friday, 15 October 2021 at 21:02:49 UTC+1, G.B. wrote:
> On 15.10.21 20:03, Dmitry A. Kazakov wrote:
> > On 2021-10-15 19:48, J-P. Rosen wrote:

>> >> Some people reserve exceptions for signalling errors. I regard them as 
>> >> a way to handle "exceptional" situations, i.e. when the normal flow of 
>> >> control cannot continue. For example, in a deep recursive search, they 
>> >> are handy to stop the recursion and go back to top level when you have 
>> >> found what you were looking for. Some would disagree with that.
>> >
>> > I strongly believe that this is the only consistent way to treat 
>> > exceptions.
>> Once found, pass the result to the party that needs it.
>> Then, finish the computational task that found the result.
>> Is there anything besides exceptions to do that, and orderly?

>I believe the ada 95 style guide recommended a standard goto?

Gotos only work within a single invocation of a single subprogram. It is 
rarely the case that some complex computation only uses one subprogram, and 
that's never the case in a recursive search (the example that J-P gave).

A program that tries to handle end-of-file by calling End_of_File all over 
is (a) way more complex than necessary, and (b) likely to be wrong as some 
case is missed. Handling End_Error makes way more sense.

Of course, if you *are* in a single subprogram, then the advice of the style 
guide is good (exceptions having more overhead than gotos, especially when 
they actually occur). They're best used when multiple subprograms (or 
subprogram calls) are involved.

                              Randy.


  reply	other threads:[~2021-10-15 22:51 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-15 15:08 Code flow control Kevin Chadwick
2021-10-15 17:48 ` J-P. Rosen
2021-10-15 18:03   ` Dmitry A. Kazakov
2021-10-15 19:19     ` Kevin Chadwick
2021-10-15 20:02     ` G.B.
2021-10-15 21:30       ` Kevin Chadwick
2021-10-15 22:51         ` Randy Brukardt [this message]
2021-10-16  7:50       ` Dmitry A. Kazakov
2021-10-16 13:26         ` Kevin Chadwick
2021-11-26 13:44           ` Kevin Chadwick
2021-10-15 17:53 ` Jeffrey R. Carter
2021-10-15 23:30 ` Roger Mc
replies disabled

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