comp.lang.ada
 help / color / mirror / Atom feed
* Newbie Q : Exception handling
@ 2001-11-27 10:04 Stella
  2001-11-28  3:13 ` DuckE
  2001-11-28 16:15 ` Jeffrey Carter
  0 siblings, 2 replies; 7+ messages in thread
From: Stella @ 2001-11-27 10:04 UTC (permalink / 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



^ permalink raw reply	[flat|nested] 7+ messages in thread
* Re: Newbie Q : Exception handling
@ 2001-11-28  8:36 Gautier Write-only-address
  0 siblings, 0 replies; 7+ messages in thread
From: Gautier Write-only-address @ 2001-11-28  8:36 UTC (permalink / raw)
  To: comp.lang.ada

>             Put("Enter num  >"); Get( Num );
>             Put("Enter quot >"); Get( Deno );

Add a "Skip_Line;" after the Get's.

>( I've tried different compilers, but that makes no difference )
A good sign, BTW...
________________________________________________________
Gautier  --  http://www.mysunrise.ch/users/gdm/gsoft.htm

NB: Do not answer to sender address, visit the Web site!


_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp




^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2001-12-12 23:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-11-27 10:04 Newbie Q : Exception handling Stella
2001-11-28  3:13 ` 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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox