From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,436ac666600e5ab3 X-Google-Attributes: gid103376,public From: randhol+nospam@pvv.org (Preben Randhol) Subject: Re: Exception Handling Date: 2000/05/29 Message-ID: #1/1 X-Deja-AN: 628806719 References: <3HCY4.29157$sB3.10828@news.indigo.ie> X-Complaints-To: usenet@itea.ntnu.no X-Trace: kopp.stud.ntnu.no 959642981 14919 129.241.83.82 (29 May 2000 23:29:41 GMT) Organization: Norwegian university of science and technology User-Agent: slrn/0.9.6.2 (Linux) NNTP-Posting-Date: 29 May 2000 23:29:41 GMT Newsgroups: comp.lang.ada Date: 2000-05-29T23:29:41+00:00 List-Id: 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] -- "Det eneste trygge stedet i verden er inne i en fortelling." -- Athol Fugard