previous page next page reference home emBASIC home page

8 Run time handlers
8.1 Introduction
Run time handlers are exception handlers which executed once event is occurred. There are two types of run time handlers: run time error handlers and message handlers.
A handler definition defines a user-defined handler object. A handler definition is an executable statement. Its execution binds the handler in the current sequence's namespace to either message or run time error.
8.2 The ON ERROR handler
In an unmonitored industrial environment it might be better to make some guess about errors that might happen and what might be done than to just shut down the system. The ON ERROR handler allows the user to act as far as he can anticipate.
The user can determine from the errcode what happened and can try to analyze what to do depending on the procedure the error happened in and on the line number (line offset from procedure start).
Runtime errors are treated as last chance exceptions. There is nor return possible from the handler. Parameters of the exception can be determined from the following system variables:
@taskname contains the name of the task/sequence in which exception has occurred
@errcode contains current error code
@taskline contains the source line on which the error has occurred.
Example[WLG16]:
ON ERROR DO
IF @errcode == $RTE_POWERFAIL THEN CALL SaveStatus
DONE