Error Handling

Material prepared from M Programming Book [WALTERS1997]

Page 347

Introduction to error handling in M with $EC[ODE] and $ET[RAP].

Command

$ECODE

Description

$ECODE is a special variable in M. In normal execution, the value of $ECODE is empty which indicates that no error has occured. However, once an error occurs, $ECODE will be set appropriately to that error. The value is comma delimited so that multiple error codes may be set, and the first character will always be a comma.

Command

$ETRAP

Description

$ETRAP is another special variable in M. The $ECODE variable only allows a developer to determine that an error has occurred, but not to recover from it. The $ETRAP variable allows a developer to define code to be triggered upon the non-empty setting of $ECODE; that is, when an error occurs, the value of $ETRAP is evaluated as code.