From: Jeffrey Carter <jrcarter@acm.org>
Subject: Re: how to check if a string variable contains a number or string?
Date: Sat, 23 Nov 2002 20:05:52 GMT
Date: 2002-11-23T20:05:52+00:00 [thread overview]
Message-ID: <3DDFDFCA.4010303@acm.org> (raw)
In-Reply-To: WjCD9.11198$8o1.1652004@news.xtra.co.nz
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
next prev parent reply other threads:[~2002-11-23 20:05 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-11-18 20:41 how to check if a string variable contains a number or string? Sarah Thomas
2002-11-18 21:09 ` Stephen Leake
2002-11-18 21:50 ` David C. Hoos
2002-11-19 0:44 ` sk
2002-11-19 1:21 ` Jeffrey Carter
2002-11-19 4:41 ` sk
2002-11-19 17:02 ` Jeffrey Carter
2002-11-24 0:10 ` AG
2002-11-23 20:05 ` Jeffrey Carter [this message]
2002-11-19 1:26 ` Jeffrey Carter
2002-11-19 3:19 ` SteveD
2002-11-19 9:38 ` Preben Randhol
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox