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,ce37dd019a007e9a X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-12-10 19:19:21 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!cyclone.bc.net!newsfeed.direct.ca!look.ca!wn1feed!wn2feed!worldnet.att.net!204.127.198.204!attbi_feed4!attbi.com!rwcrnsc54.POSTED!not-for-mail From: "Steve Doiel" Newsgroups: comp.lang.ada References: Subject: Re: Incompatible type error 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: Tue, 11 Dec 2001 03:19:20 GMT NNTP-Posting-Host: 204.127.202.216 X-Complaints-To: abuse@attbi.com X-Trace: rwcrnsc54 1008040760 204.127.202.216 (Tue, 11 Dec 2001 03:19:20 GMT) NNTP-Posting-Date: Tue, 11 Dec 2001 03:19:20 GMT Organization: AT&T Broadband Xref: archiver1.google.com comp.lang.ada:17731 Date: 2001-12-11T03:19:20+00:00 List-Id: Here is a small sample program that illustrates some crude error handling, but you may find some suprises: with Ada.Integer_Text_Io; with Ada.Float_Text_io; with Ada.Text_io; procedure Input_Demo is integer_value : Integer; float_value : Float; begin loop begin Ada.Text_Io.Put( "Enter an Integer > " ); Ada.Integer_Text_Io.Get( integer_value ); Ada.Text_Io.Skip_Line; exit; exception when others => Ada.Text_Io.Put_Line( "That's not a valid integer" ); Ada.Text_Io.Skip_Line; end; end loop; Ada.Text_Io.Put( "You entered " ); Ada.Integer_Text_Io.Put( integer_value ); Ada.Text_Io.New_Line; loop begin Ada.Text_Io.Put( "Enter a floating point value > " ); Ada.Float_Text_Io.Get( float_value ); Ada.Text_Io.Skip_Line; exit; exception when others => Ada.Text_Io.Put_Line( "That's not a valid floating point value" ); Ada.Text_Io.Skip_Line; end; end loop; Ada.Text_Io.Put( "You entered " ); Ada.Float_Text_Io.Put( float_value ); Ada.Text_Io.New_Line; end Input_Demo; -------- Try a few of the following cases in response to each of the prompts: abc 123 123.45 If you more control over what is accepted, I suggest you read the input into a string, validate the input string, and then convert to the appropriate type. SteveD "Ben" wrote in message news:bf8dbe70.0112101352.20a3d257@posting.google.com... > Hi, > > I am new to Ada and the instruction book I found is not really helpful > in explaining how to handle errors of unmatching types. For example, > one of the sample problems the book has me do it a simple calculator > made to work with real values. Say I programmed it to work only with > integers, yet I enter a real number. That will cause a problem, > right? Is the error handling automatic in Ada, or do I need to code > something in. So far I have been unsuccessful at finding example code > and instructions on how to do this. > > Thanks, > Ben