Hamster-Scripts: Functions (built-in)

Error-handling

ErrCatch( <on/off> )

ErrCatch

If <on/off> is TRUE (<>0), error-catching is enabled. This means, that all errors, which normally stop the script immediately, are ignored. If an error happens in this state, "ErrNum" will return a value other than 0.

If <on/off> is FALSE (=0), error-catching is disabled again, i.e. the script will be stopped again if an error happens.

"ErrCatch" without parameters just returns the current state. It may be used to preserve the current state while executing a "dangerous" part of a script.

Returns: 0/False: Disabled (default; i.e. stop on errors), 1/True: Enabled (ignore errors)

$OldErrCatch = ErrCatch
ErrCatch( True )
print( 42/0 )  # division by zero causes error
if( ErrNum<>0 )
   print( "Error: ", ErrNum, " ", ErrMsg )
endif
ErrCatch( $OldErrCatch )

ErrNum

Returns error-number of last error.

NOTE: Do not rely on the numbers returned, they might be changed in a future version.

Returns: Integer (=0: No error, <>0: Error)

if( ErrNum <> 0 )
   # ...
endif

ErrMsg

Returns error-description of last error.

Returns: String

print( ErrMsg )

ErrModule

Returns name of module in which last error occured.

Returns: String

print( ErrModule )

ErrLineNo

Returns line number within module in which last error occured.

Returns: Integer

print( ErrLineNo )

ErrLine

Returns script-line which raised last error.

Returns: String

print( ErrLine )

ErrSender

Returns name of script-object which raised last error.

Returns: String

print( ErrSender )

[www.elbiah.de Hamster Playground Documentation]