From: "Jeffrey D. Cherry" <jdcherry@utech.net>
To: "David C. Hoos, Sr." <david.c.hoos.sr@ada95.com>
Subject: Re: Exception Handling
Date: 2000/06/02
Date: 2000-06-02T00:00:00+00:00 [thread overview]
Message-ID: <3937CC62.957177F6@utech.net> (raw)
In-Reply-To: aJLZ4.4563$kV6.188069@newsread1.prod.itd.earthlink.net
"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
next prev parent reply other threads:[~2000-06-02 0:00 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2000-05-29 0:00 Exception Handling NANCY HEHIR
2000-05-29 0:00 ` Preben Randhol
2000-05-30 0:00 ` Antonio Dur�n Dom�nguez
2000-05-30 0:00 ` Jeffrey D. Cherry
2000-05-30 0:00 ` Gautier
2000-06-05 0:00 ` Robert Dewar
2000-06-01 0:00 ` Preben Randhol
2000-06-01 0:00 ` Preben Randhol
2000-06-01 0:00 ` Jeffrey D. Cherry
2000-06-02 0:00 ` David C. Hoos, Sr.
2000-06-02 0:00 ` Jeffrey D. Cherry [this message]
2000-06-01 0:00 ` Ehud Lamm
2000-06-01 0:00 ` Jeff Carter
2000-06-02 0:00 ` Jeffrey D. Cherry
2000-06-02 0:00 ` Preben Randhol
2000-05-30 0:00 ` Robert Dewar
-- strict thread matches above, loose matches on Subject: below --
1996-09-28 0:00 Robert Dewar
1996-09-17 0:00 John Goodenough
1996-09-17 0:00 Marin David Condic, 407.796.8997, M/S 731-93
1996-09-19 0:00 ` Larry Kilgallen
1996-09-13 0:00 Marin David Condic, 407.796.8997, M/S 731-93
1996-09-15 0:00 ` Larry Kilgallen
1996-09-23 0:00 ` Robin Vowels
1996-09-12 0:00 Robbie Gates
1996-09-12 0:00 ` Patrick Doyle
1996-09-12 0:00 ` Rick Decker
1996-09-13 0:00 ` Larry Kilgallen
1996-09-12 0:00 ` Bryce
1996-09-12 0:00 ` Larry Kilgallen
1996-09-13 0:00 ` Robbie Gates
1996-09-14 0:00 ` Paul A. Houle
1996-09-18 0:00 ` Rick Decker
1996-09-13 0:00 ` Felix Kasza
1996-09-13 0:00 ` David B. Shapcott [C]
1996-09-18 0:00 ` Bart Termorshuizen
1996-09-16 0:00 ` Norman H. Cohen
1996-09-23 0:00 ` Robin Vowels
1996-09-24 0:00 ` Bob Halpern
1996-10-02 0:00 ` Fritz Schneider
1996-10-07 0:00 ` Robin Vowels
1996-10-09 0:00 ` shmuel
1996-10-09 0:00 ` Bob Halpern
1996-09-26 0:00 ` Thiago
1986-05-13 22:57 exception handling MIXSIM
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox