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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,436ac666600e5ab3 X-Google-Attributes: gid103376,public From: "Jeffrey D. Cherry" Subject: Re: Exception Handling Date: 2000/06/02 Message-ID: <3937CC62.957177F6@utech.net>#1/1 X-Deja-AN: 630246578 Content-Transfer-Encoding: 7bit References: <3HCY4.29157$sB3.10828@news.indigo.ie> <3933DAF3.35F40B3A@utech.net> <393677C0.E1A2457F@utech.net> To: "David C. Hoos, Sr." X-Accept-Language: en,pdf Content-Type: text/plain; charset=us-ascii X-Trace: azure.impulse.net 959958278 192 207.154.67.27 Organization: Logicon MIME-Version: 1.0 Newsgroups: comp.lang.ada Date: 2000-06-02T00:00:00+00:00 List-Id: "David C. Hoos, Sr." wrote: > > I'm curious as to why you wouldn't simply use the 'Value > attribute of the specific type to attempt the conversion. > This avoids the expense of an instance of Text_IO.Float_IO > which might be needed for no other purpose, and makes use > of the compiler vendor's parsing routine. The reason is that the 'Value attribute raises Constraint_Error if there is something wrong with the syntax of the input string while the Get procedure from Ada.Float_Text_IO raises Data_Error. Constraint_Error can be suppressed while Data_Error cannot. One other thing, while I was looking at the Get_Float procedure I posted I noticed an error. The assignment statement following the call to Get is incorrect. The corrected procedure is: procedure Get_Float(St : in string; Value : out float; Is_Valid : out boolean) is Last : positive; begin -- Get_Float Ada.Float_Text_IO.Get(St, Value, Last); Is_Valid := Last = St'last; exception when others => Is_Valid := false; end Get_Float; The reason the previous version was wrong is that parameter Last will contain the index of the last character read during the conversion. For the example string of "2.3W-4", Last would be set to 3, Is_Valid would have erroneously been set to true, and Value would be 2.3 rather than 0.00023. In the corrected version (above), Is_Valid is set to true only if the entire input string is consumed during the conversion. -- Regards, Jeffrey D. Cherry Senior IV&V Analyst Logicon Space and Information Operations Logicon Inc. a Northrop Grumman company