// an undesirable feature ... when
// entering numbers via string input first
// if '1234567' is entered in the first loop, and
// then just an empty line entered on the next loops,
// the program prints out '567' each loop
// (and doesn't throw any exception)
// tested with HLA 1.101 and 1.102
// with Win XP 2008-04-29
program conv_strToi32_exceptionHandling;
#include( "stdlib.hhf" )
static
inStr: string;
i32: int32;
begin conv_strToi32_exceptionHandling;
forever
try
stdout.put( "Testing 'input number as string' : " );
stdin.flushInput();
stdin.a_gets();
mov( eax, inStr );
conv.strToi32( inStr, 0 );
mov( eax, i32 );
stdout.put( nl "i32 = ", i32, nl nl );
exception( ex.ConversionError )
stdout.puts
(
nl "Input value contained illegal characters.
Re-enter. " nl
);
exception( ex.ValueOutOfRange )
stdout.puts
(
nl "Input value was NOT in an acceptable range.
Re-enter. " nl
);
exception( ex.AccessViolation )
stdout.puts
(
nl "Input error ... Need to enter some number.
Re-enter. " nl
);
endtry;
str.cpy( "", inStr );
str.free( inStr );
endfor;
end conv_strToi32_exceptionHandling;
Logged In: YES
user_id=2022655
Originator: YES
File Added: conv_strTou32_exceptionHandling.hla
"mystrTou32.hhf" handles two problem cases
HHF include FILE needed for calls to mystrTou32( srcStr, 0)
Logged In: YES
user_id=2022655
Originator: YES
File Added: mystrTou32.hhf