comp.lang.ada
 help / color / mirror / Atom feed
From: Anonymous Coward <anonymous@coward.org>
Subject: Puzzling small piece of code - exception block essentially used as goto
Date: Sat, 02 Jun 2007 05:01:15 GMT
Date: 2007-06-02T05:01:15+00:00	[thread overview]
Message-ID: <vQ68i.99$UD4.49@trndny07> (raw)

This is an excerpt from some code I recently encountered (it may give
some of you a headache):

  Still_Looping := True;

  Delta_Beyond_Max_Minutes:
    while Still_Looping loop

      Handle_Max_Minute_Error:
        begin

          Hour_Delta    := New_Hour - Hour;
          Still_Looping := False;
          Hour          := New_Hour;

        exception
          when Constraint_Error =>

            if New_Hour > Hour then

              Hour_Delta := Max_Hour_Delta

            else

              Hour_Delta := Relative_Time - Max_Hour_Delta;

            end if;

            Hour := Hour + Hour_Delta;

        end Handle_Max_Minute_Error;
    end loop Delta_Beyond_Max_Minutes;

Tests show that this code actually loops a few times when run in a
typical state.  What I would like clarification on is when the
exception block ends, where is control returned to?

Also, anyone up for the challenge of rewriting this without the
exception handler so the rest of us humans can understand what it's
doing?



             reply	other threads:[~2007-06-02  5:01 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-02  5:01 Anonymous Coward [this message]
2007-06-02  5:48 ` Puzzling small piece of code - exception block essentially used as goto Jeffrey R. Carter
2007-06-05  2:38   ` Anonymous Coward
2007-06-05  4:10     ` tmoran
2007-06-05  4:53       ` tmoran
2007-06-02  6:16 ` tmoran
2007-06-05  0:08 ` Adam Beneschan
2007-06-05  7:58 ` anon
2007-06-05 10:40   ` Markus E Leypold
2007-06-05 23:43   ` Anonymous Coward
2007-06-06 10:39     ` Markus E Leypold
2007-06-08  0:55       ` Anonymous Coward
2007-06-08  2:22         ` Markus E Leypold
replies disabled

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