From: bt_are_shite@talk21.com (Stella)
Subject: Newbie Q : Exception handling
Date: Tue, 27 Nov 2001 10:04:42 GMT
Date: 2001-11-27T23:42:28+00:00 [thread overview]
Message-ID: <3c035fe0.7469961@news.freeserve.net> (raw)
Hi All,
Having a strange problem using exceptions. It's ( I presume) a pretty
basic question.
Here's the code:-
-- This program does nothing, and is just an example to indicate
-- the exception handling problem...
with Text_Io, Ada.Integer_Text_Io;
use Text_Io, Ada.Integer_Text_Io;
procedure Exception_Handling2 is
type Units is ( Ins, Ft, Yd, Mil, Mm, Cm, M, Km, Oz, Lbs, G, Kg );
Num, Deno, Quot : Units;
package Units_Io is new Enumeration_Io( Units );
use Units_Io;
begin
loop
begin
Put("Enter num >"); Get( Num );
Put("Enter quot >"); Get( Deno );
Quot :=Num;
exit;
exception
when Data_Error => Put_Line("Wrong_d!");
when Constraint_Error => Put_Line("Wrong_c");
when others => Put_Line("Wrong_o");
end;
New_Line;
end loop;
Put("The result is "); Put( Quot,1 ); New_Line;
end Exception_Handling2;
What happens is that if I enter a garbage value ( i.e. hello ), it
traps the data_error problem fine, and asks for the data again, but if
I enter 0 or any number, it traps the error, but just goes round in an
infinite loop, i.e.
Enter num > Wrong_d!
Enter num > Wrong_d!
Enter num > Wrong_d!
Enter num > Wrong_d!
etc etc etc
i.e. it doesn't stop at the get(), but just seems to skip over that
line. I've tried flush() to maybe get round any buffer problems, but
that does nothing.
I've found it seems to occur when numbers are input when strings are
expected and vice-versa.
Any pointers would be gratefully recieved...
( I've tried different compilers, but that makes no difference )
Stella
next reply other threads:[~2001-11-27 10:04 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-11-27 10:04 Stella [this message]
2001-11-28 3:13 ` Newbie Q : Exception handling DuckE
2001-11-28 3:31 ` Stella
2001-11-28 16:15 ` Jeffrey Carter
2001-11-30 18:39 ` Matthew Heaney
2001-12-12 23:40 ` Stella
-- strict thread matches above, loose matches on Subject: below --
2001-11-28 8:36 Gautier Write-only-address
replies disabled
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox