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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,5c8c86891defe3dc X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-11-27 19:13:27 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!sn-xit-01!supernews.com!newshub2.rdc1.sfba.home.com!news.home.com!news1.sttln1.wa.home.com.POSTED!not-for-mail From: "DuckE" Newsgroups: comp.lang.ada References: <3c035fe0.7469961@news.freeserve.net> Subject: Re: Newbie Q : Exception handling X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4522.1200 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4522.1200 Message-ID: Date: Wed, 28 Nov 2001 03:13:27 GMT NNTP-Posting-Host: 24.248.45.203 X-Complaints-To: abuse@home.net X-Trace: news1.sttln1.wa.home.com 1006917207 24.248.45.203 (Tue, 27 Nov 2001 19:13:27 PST) NNTP-Posting-Date: Tue, 27 Nov 2001 19:13:27 PST Organization: Excite@Home - The Leader in Broadband http://home.com/faster Xref: archiver1.google.com comp.lang.ada:17077 Date: 2001-11-28T03:13:27+00:00 List-Id: Try adding a Skip_Line to your exception handler. SteveD "Stella" wrote in message news:3c035fe0.7469961@news.freeserve.net... > 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