2022-09-29

restoring the exception environment

Can anyone explain the concept of restoring the exception environment simply and smoothly.

It is said that when we use the exception handler in the try...endtry statement،When the program reaches the endtry, it restores the exception environment, but if it suddenly encounters a break command, for example, this recovery does not take place. And the program even after exiting the try.......endtry command thinks that it is in the previous exception environment, and if another error occurs, it returns to the previous try......endtry command.

Like the following code snippet:

program testBadInput3;
#include( "stdlib.hhf" )
static
input: int32; 
begin testBadInput3;
 // This forever loop repeats 
//until the user enters
// a good integer and the 
break 
//statement below
// exits the loop.

forever

try
stdout.put( "Enter an integer 
value: " );
stdin.get( input );
stdout.put( "The first input 
value was: ", input, nl );

break;

exception( ex.ValueOutOfRange 
)

stdout.put( "The value was too 
large, re-enter." nl );

exception( ex.ConversionError 
)

stdout.put( "The input 
contained illegal characters, 
re-enter." nl );

endtry;

endfor;

// Note that the following 
code //is outside the loop and 
there
// is no try..endtry statement 
//protecting this code.

stdout.put( "Enter another 
number: " );
stdin.get( input );
stdout.put( "The new number 
is: 
", input, nl );
end testBadInput3;


No comments:

Post a Comment