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.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,e584b80ec129f1ce,start X-Google-Attributes: gid103376,public From: Amun-Ra Subject: Exception handling problem Date: 2000/03/06 Message-ID: <38C34C24.3955@gmx.net> X-Deja-AN: 593662610 Content-Transfer-Encoding: 7bit Organization: Regionales Rechenzentrum Erlangen, Germany Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 Newsgroups: comp.lang.ada Date: 2000-03-06T00:00:00+00:00 List-Id: Hi all! I have a big problem handling exceptions with Ada95 using GNAT. I need to enter a number and, if something else is entered, the raised exception Ada.IO_Exceptions.Data_Error has to be handled and the asking for a number should continue (I guess the problem is probably simple, but I don't see a solution yet). The code I am worrying about is the following: -- Procedure "RAS_AskBreakpoint": -- Asks if a breakpoint should be set or unset. It returns 0 if the -- breakpoint should be unset, 1 if it should be set and also returns the -- entered breakpoint value as out-argument. -- procedure RAS_AskBreakpoint (Input: out Long_Long_Integer; Mode: out Integer) is Keystroke: Character; begin RAS_Set_Position (Position => (Col => 1, Line => 10)); Put (EmptyLine); RAS_Set_Position (Position => (Col => 1, Line => 10)); Put ("Do you want to set or unset a breakpoint?"); RAS_Set_Position (Position => (Col => 1, Line => 10)); loop Get_Immediate (Keystroke); if Keystroke = 'S' or Keystroke = 's' then Mode := 1; Put (EmptyLine); RAS_Set_Position (Position => (Col => 1, Line => 10)); Put ("Set breakpoint at which instruction (<0 to abort): "); Get (Input); exit; elsif Keystroke = 'U' or Keystroke = 'u' then Mode := 0; Put (EmptyLine); RAS_Set_Position (Position => (Col => 1, Line => 10)); Put ("Unset which breakpoint (<0 to abort): "); Get (Input); exit; end if; end loop; RAS_Set_Position (Position => (Col => 1, Line => 10)); Put (EmptyLine); RAS_Set_Position (Position => (Col => 1, Line => 11)); end RAS_AskBreakpoint; This procedure can be called many times and of course the only inputs that need to be done are a 'S'|'s' or 'U'|'u' and subsequently a number of type Long_Long_Integer. The only lines where the Data_Error can occur, are the "Get (Input);"-lines. However, if a Data_Error is raised, the asking for a number should continue until the user enters a valid number. I already tried handling the exception by declaring another block inside the loop...end loop-section with own exception handler: loop begin Get_Immediate (Keystroke); if Keystroke = 'S' or Keystroke = 's' then Mode := 1; Put (EmptyLine); RAS_Set_Position (Position => (Col => 1, Line => 10)); Put ("Set breakpoint at which instruction (<0 to abort): "); Get (Input); exit; elsif Keystroke = 'U' or Keystroke = 'u' then Mode := 0; Put (EmptyLine); RAS_Set_Position (Position => (Col => 1, Line => 10)); Put ("Unset which breakpoint (<0 to abort): "); Get (Input); exit; end if; exception when others => Put_Line ("Enter a number!"); end; end loop; as well as trying to localize the exception handling down to the Get-Instruction: loop begin Get (Input); exit; exception when others => Put_Line ("Enter a number!"); end; end loop; The behaviour of the procedure then (regardless of where in the loop I put the handler) is always the same: If I enter a number as wanted, I can call the procedure as often as I want and it works perfectly. However, if I enter something else, like a letter (I want to trap typing errors), upon subsequent calls of the procedure, the "Get (Input)"- Statements are no longer executed (the Put-Statements immediately in front of them are executed), so I cannot enter a number anymore. And strange enough, the Put_Line-statement in the exception handler is not executed in the first code snippet, but leads to an infinite loop in the second one. I already thought of doing a "Flush;" in the exception handler, but that did not work either. Does anyone know why that strange behaviour occurs, why after giving wrong Input the "Get (Input);"s are no longer executed upon calling the procedure again and why the exception is not handled as wanted??? Can anyone tell me, where I made a mistake and how the code must be written so that I can keep asking for a number if I mistyped??? I would appreciate any hints!!! Thanks in advance!!! Andreas P.S. Could you please also send answers via e-mail to: Amun_Ra72@gmx.net Thanks!