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=-0.3 required=5.0 tests=BAYES_00,FREEMAIL_FROM, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,5c8c86891defe3dc,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-11-27 15:42:29 PST Path: archiver1.google.com!news1.google.com!sn-xit-02!supernews.com!news.tele.dk!small.news.tele.dk!212.74.64.35!colt.net!diablo.theplanet.net!news.theplanet.net!not-for-mail From: bt_are_shite@talk21.com (Stella) Newsgroups: comp.lang.ada Subject: Newbie Q : Exception handling Date: Tue, 27 Nov 2001 10:04:42 GMT Organization: yes Message-ID: <3c035fe0.7469961@news.freeserve.net> Reply-To: bt_are_shite@talk21.com NNTP-Posting-Host: modem-671.bonobo.dialup.pol.co.uk X-Trace: news5.svr.pol.co.uk 1006904548 8477 217.134.50.159 (27 Nov 2001 23:42:28 GMT) NNTP-Posting-Date: 27 Nov 2001 23:42:28 GMT X-Complaints-To: abuse@theplanet.net X-Newsreader: Forte Free Agent 1.21/32.243 Xref: archiver1.google.com comp.lang.ada:17071 Date: 2001-11-27T23:42:28+00:00 List-Id: Hi All, Having a strange problem using exceptions. It's ( I presume) a pretty basic question. Here's the code:- -- This program does nothing, and is just an example to indicate -- the exception handling problem... with Text_Io, Ada.Integer_Text_Io; use Text_Io, Ada.Integer_Text_Io; procedure Exception_Handling2 is type Units is ( Ins, Ft, Yd, Mil, Mm, Cm, M, Km, Oz, Lbs, G, Kg ); Num, Deno, Quot : Units; package Units_Io is new Enumeration_Io( Units ); use Units_Io; begin loop begin Put("Enter num >"); Get( Num ); Put("Enter quot >"); Get( Deno ); Quot :=Num; exit; exception when Data_Error => Put_Line("Wrong_d!"); when Constraint_Error => Put_Line("Wrong_c"); when others => Put_Line("Wrong_o"); end; New_Line; end loop; Put("The result is "); Put( Quot,1 ); New_Line; end Exception_Handling2; What happens is that if I enter a garbage value ( i.e. hello ), it traps the data_error problem fine, and asks for the data again, but if I enter 0 or any number, it traps the error, but just goes round in an infinite loop, i.e. Enter num > Wrong_d! Enter num > Wrong_d! Enter num > Wrong_d! Enter num > Wrong_d! etc etc etc i.e. it doesn't stop at the get(), but just seems to skip over that line. I've tried flush() to maybe get round any buffer problems, but that does nothing. I've found it seems to occur when numbers are input when strings are expected and vice-versa. Any pointers would be gratefully recieved... ( I've tried different compilers, but that makes no difference ) Stella