Menu

#36 undesirable feature when using conv_strToXXX

open
nobody
None
5
2008-04-29
2008-04-29
No

// 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;

Discussion

  • David W. Zavitz

    David W. Zavitz - 2008-05-01

    Logged In: YES
    user_id=2022655
    Originator: YES

    File Added: conv_strTou32_exceptionHandling.hla

     
  • David W. Zavitz

    David W. Zavitz - 2008-05-01

    "mystrTou32.hhf" handles two problem cases

     
  • David W. Zavitz

    David W. Zavitz - 2008-05-01

    HHF include FILE needed for calls to mystrTou32( srcStr, 0)

     
  • David W. Zavitz

    David W. Zavitz - 2008-05-01

    Logged In: YES
    user_id=2022655
    Originator: YES

    File Added: mystrTou32.hhf

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.