From: randhol+nospam@pvv.org (Preben Randhol)
Subject: Re: Exception Handling
Date: 2000/05/29
Date: 2000-05-29T23:29:41+00:00 [thread overview]
Message-ID: <slrn8j5vbk.6t0.randhol+nospam@kiuk0156.chembio.ntnu.no> (raw)
In-Reply-To: 3HCY4.29157$sB3.10828@news.indigo.ie
On Mon, 29 May 2000 23:53:18 +0100, NANCY HEHIR wrote:
>The Ada language reference manual (chapter 11) indicates that when an
>exception is raised the main body of code is abandoned and that if code
>exists for handling the exception then this is executed.
>
>Is it possible to use the exception handler to return to the main body at a
>point before the point where the exception is raised?
>
>For example: If I prompt for a keyboard input of ,say an eight character
>string, and a seven char string is actually inputted, a Constraint_Error is
>raised. Can I use a handling device to return the execution to the prompt
>for input ?
Yes by using a loop around a begin exception end block.
This is from the top of my head so it might not work without
modifications:
loop
begin -- This is the start of the block
read_from_keyboard;
exit; -- The code won't reach here if Constraint_Error is
-- raised by the previous function.
exception
when E : Constraint_Error =>
Put_Line("Wrong input, try again!");
end;
end loop;
Note it might increase readability a bit if you did something like this
(I'm not sure):
correct_input : boolean := false;
[...]
loop
begin -- This is the start of the block
read_from_keyboard;
correct_input := true;
exception
when E : Constraint_Error =>
Put_Line("Wrong input, try again!");
end;
exit when correct_input;
end loop;
Also note that you can use :
Input_String : String(1..30);
Length : Natural := 0;
[...]
Ada.Text_IO.Get_Line(Item => Input_String, Last => Length);
then you can use:
Input_String(1..Length)
I would recommend that you read the "Ada 95 Problem Solving and Program
Design", 3rd ed. by Feldman and Koffman. For a nice introduction to Ada.
More info can be found here:
http://www.seas.gwu.edu/faculty/mfeldman/cs1book
--
Preben Randhol -- [randhol@pvv.org] -- <http://www.pvv.org/~randhol/>
"Det eneste trygge stedet i verden er inne i en fortelling."
-- Athol Fugard
next prev parent reply other threads:[~2000-05-29 0:00 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-05-29 0:00 Exception Handling NANCY HEHIR
2000-05-29 0:00 ` Preben Randhol [this message]
2000-05-30 0:00 ` Antonio Dur�n Dom�nguez
2000-05-30 0:00 ` Jeffrey D. Cherry
2000-05-30 0:00 ` Gautier
2000-06-05 0:00 ` Robert Dewar
2000-06-01 0:00 ` Preben Randhol
2000-06-01 0:00 ` Preben Randhol
2000-06-01 0:00 ` Ehud Lamm
2000-06-01 0:00 ` Jeffrey D. Cherry
2000-06-02 0:00 ` David C. Hoos, Sr.
2000-06-02 0:00 ` Jeffrey D. Cherry
2000-06-01 0:00 ` Jeff Carter
2000-06-02 0:00 ` Jeffrey D. Cherry
2000-06-02 0:00 ` Preben Randhol
2000-05-30 0:00 ` Robert Dewar
-- strict thread matches above, loose matches on Subject: below --
1996-09-28 0:00 Robert Dewar
1996-09-17 0:00 Marin David Condic, 407.796.8997, M/S 731-93
1996-09-19 0:00 ` Larry Kilgallen
1996-09-17 0:00 John Goodenough
1996-09-13 0:00 Marin David Condic, 407.796.8997, M/S 731-93
1996-09-15 0:00 ` Larry Kilgallen
1996-09-23 0:00 ` Robin Vowels
1996-09-12 0:00 Robbie Gates
1996-09-12 0:00 ` Patrick Doyle
1996-09-12 0:00 ` Rick Decker
1996-09-13 0:00 ` Larry Kilgallen
1996-09-12 0:00 ` Bryce
1996-09-12 0:00 ` Larry Kilgallen
1996-09-13 0:00 ` Robbie Gates
1996-09-14 0:00 ` Paul A. Houle
1996-09-18 0:00 ` Rick Decker
1996-09-13 0:00 ` Felix Kasza
1996-09-13 0:00 ` David B. Shapcott [C]
1996-09-18 0:00 ` Bart Termorshuizen
1996-09-16 0:00 ` Norman H. Cohen
1996-09-23 0:00 ` Robin Vowels
1996-09-24 0:00 ` Bob Halpern
1996-10-02 0:00 ` Fritz Schneider
1996-10-07 0:00 ` Robin Vowels
1996-10-09 0:00 ` shmuel
1996-10-09 0:00 ` Bob Halpern
1996-09-26 0:00 ` Thiago
1986-05-13 22:57 exception handling MIXSIM
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox