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,8dd8ee71ca4e5206 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-10-03 12:43:33 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.tele.dk!small.news.tele.dk!129.240.148.23!uio.no!ntnu.no!not-for-mail From: Preben Randhol Newsgroups: comp.lang.ada Subject: Re: Newbie question on Ada TExt_IO Date: Thu, 3 Oct 2002 19:43:32 +0000 (UTC) Organization: Norwegian university of science and technology Message-ID: References: <93d4dcd4.0210031020.b0cca2b@posting.google.com> NNTP-Posting-Host: kiuk0156.chembio.ntnu.no X-Trace: tyfon.itea.ntnu.no 1033674212 15547 129.241.83.82 (3 Oct 2002 19:43:32 GMT) X-Complaints-To: usenet@itea.ntnu.no NNTP-Posting-Date: Thu, 3 Oct 2002 19:43:32 +0000 (UTC) User-Agent: slrn/0.9.7.4 (Linux) Xref: archiver1.google.com comp.lang.ada:29502 Date: 2002-10-03T19:43:32+00:00 List-Id: On 3 Oct 2002 11:20:24 -0700, Justin wrote: > How can I handle this? From my take on what I've read I should avoid > exception handling for things I'm not expecting, so I've ruled out > exceptions, that leaves me with obtaining a value of generic type and > evalutating the type at run-time...how can I do this? Is this the > right strategy? No I would have used exceptions here. I find it difficult to see how you can avoid it. I recommend that you look at http://www.it.bton.ac.uk/staff/je/adacraft/ because it has a lot of nice examples to start with. Here is my implementation: --------------------------------------------------------------- with Ada.Text_IO; use Ada.Text_IO; procedure Feedback is Input : String(1..80); Last : Integer; begin -- This example will loop until you give a correct number loop Put ("Please enter a number between 1 and 6 : "); Get_Line (Item => Input, Last => Last); -- I now choose a block because then I can -- put a exception handler inside so that you will -- be asked for a number until you give a correct -- number declare -- Making a type that is from 1 to 6. If the character -- you convert isn't in the range 1..6 then Constraint_Error -- will be raised and we can handle it. type Input_Number_Type is range 1..6; Number : Input_Number_Type; begin -- we convert Input (1..1) to our Input_Number_Type Number := Input_Number_Type'Value (Input (1..1)); Put_Line ("Thank you!"); -- OK conversion went well. (If it hadn't the program would -- jump to exception below before instead of continuing) exit; -- Jumping out of the loop. exception when Constraint_Error => Put_Line ("Wrong number!"); end; end loop; end Feedback; Preben -- Ada95 is good for you. http://libre.act-europe.fr/Software_Matters/02-C_pitfalls.pdf