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,e5221eea63340249 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-11-23 12:06:54 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!headwall.stanford.edu!newsfeed.news2me.com!newsfeed2.earthlink.net!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!newsread1.prod.itd.earthlink.net.POSTED!not-for-mail Message-ID: <3DDFDFCA.4010303@acm.org> From: Jeffrey Carter User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:1.0.0) Gecko/20020530 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: how to check if a string variable contains a number or string? References: <3DD99222.5010904@acm.org> <3DDA6EE2.2010409@acm.org> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Date: Sat, 23 Nov 2002 20:05:52 GMT NNTP-Posting-Host: 63.184.105.0 X-Complaints-To: abuse@earthlink.net X-Trace: newsread1.prod.itd.earthlink.net 1038081952 63.184.105.0 (Sat, 23 Nov 2002 12:05:52 PST) NNTP-Posting-Date: Sat, 23 Nov 2002 12:05:52 PST Organization: EarthLink Inc. -- http://www.EarthLink.net Xref: archiver1.google.com comp.lang.ada:31189 Date: 2002-11-23T20:05:52+00:00 List-Id: AG wrote: > Tst, tsk... If you use an existing subprogram that may > raise an exception - don't you have to write some new > code to handle that exception? And don't you have to > provide some sort of recovery perhaps to simulate the > non-exception version? Perhaps you've discovered some way to use an existing subprogram without writing any "new" code? More to the point, which is a better use of your valuable resources: with Parser; ... begin Number := Parser.Parse (Image); -- process Number exception when Parser.Invalid_Image => Error ("Invalid number: " & Image); end; or type Parse_Result (Valid : Boolean := False) is record case Valid is when False => null; when True => Number : Numeric_Value; end case; end record; function Parse (Image : String) return Parse_Result is -- Many -- declarations -- for -- a -- complex -- parsing -- algorithm -- identical -- to -- Parser.Parse -- except -- for -- error -- handling begin -- Parse -- a -- very -- long -- and -- complex -- algorithm -- for -- parsing -- the -- character -- representation -- of -- a -- number, -- identical -- to -- Parser.Parse -- except -- for -- error -- handling end Parse; ... Result : Parse_Result; ... Result := Parse (Image); if Result.Valid then -- process Result.Number else Error ("Invalid number: " & Image); end if; ? -- Jeff Carter "I'm a lumberjack and I'm OK." Monty Python's Flying Circus