Class RTS_CatchingErrors
java.lang.Object
simula.runtime.RTS_RTObject
simula.runtime.RTS_ENVIRONMENT
simula.runtime.RTS_BASICIO
simula.runtime.RTS_CLASS
simula.runtime.RTS_CatchingErrors
- All Implemented Interfaces:
Runnable
Additional System class CatchingErrors.
This class is used to implement runtime error catching. The basic idea is to enclose the 'inner' statement by a Java try-catch construction and, in the catch section to call a virtual procedure 'onError' to deal with the error situation.
To achieve this, the class CatchingErrors is hand-coded as a standard class.
class CatchingErrors; virtual: procedure onError; begin -- code: try { inner; -- code: } catch(RuntimeException e) { -- code: _CUR=this; // As iff non-local goto here -- code: _onError(e,onError); -- code: } end;
Usage:
CatchingErrors begin procedure onError(message); text message; begin ... treating error end; ... any error here will cause calling onError end;
There are three ways to return from the procedure onError:
-
goto a non-local label.
-
calling terminate_program or error
-
falling through procedure end which has the same effect as ending the prefixed block.
Example: Safe version of getint returns maxint when it fails.
integer procedure safeGetint(t); text t; begin CatchingErrors begin procedure onError(message); text message; begin safeGetint:=maxint; end; safeGetint:=t.getint; end; end;
Link to GitHub: Source File.
- Author:
- Øystein Myhre Andersen
-
Field Summary
Fields inherited from class simula.runtime.RTS_ENVIRONMENT
_STARTTIME, CURRENTDECIMALMARK, CURRENTLOWTEN, EXCEPTION_HANDLER, maxint, maxlongreal, maxreal, minint, minlongreal, minreal, simulaReleaseID
Fields inherited from class simula.runtime.RTS_RTObject
_CORUT, _CTX, _CUR, _DL, _INPUT_LINELENGTH, _JTX, _OUTPUT_LINELENGTH, _SL, _STATE, _SYSIN, _SYSOUT, _USR, startTimeMs
-
Constructor Summary
ConstructorsConstructorDescriptionRTS_CatchingErrors
(RTS_RTObject staticLink) Create a new _CatchingErrors instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
_onError
(RuntimeException e, RTS_PRCQNT match) This method is called when a RuntimeException occur.Default virtual match for procedure onError.Methods inherited from class simula.runtime.RTS_BASICIO
terminate_program, toString
Methods inherited from class simula.runtime.RTS_ENVIRONMENT
_char, abs, abs, abs, addepsilon, addepsilon, arccos, arcsin, arctan, arctan2, argv, blanks, Char, clocktime, copy, cos, cosh, cotan, cputime, datetime, decimalmark, DEFEXCEPTION, digit, discrete, draw, edfix, edfix, edit, edit, edit, edit, edit, edit, edtime, edtime, entier, Erlang, error, exit, exp, hash, histd, histo, isochar, isorank, letter, linear, ln, loadChar, log10, lowcase, lowerbound, lowten, max, max, max, max, max, max, max, max, max, max, max, min, min, min, min, min, min, min, min, min, min, min, mod, negexp, normal, Poisson, printStaticChain, printThreadList, randint, rank, rem, sign, simulaid, sin, sinh, sqrt, storeChar, subepsilon, subepsilon, tan, tanh, uniform, upcase, upperbound, waitSomeTime
Methods inherited from class simula.runtime.RTS_RTObject
_GOTO, _JUMPTABLE, _SIM_LABEL, _STM, _TREAT_GOTO_CATCH_BLOCK, _VALUE, arrayValue, BBLK, booleanValue, call, call, charValue, CONC, detach, detach, detach, doubleValue, EBLK, edObjectAttributes, edObjectIdent, floatValue, intValue, isDetachUsed, isQPSystemBlock, objectTraceIdentifier, objectTraceIdentifier, objectValue, procValue, resume, resume, resume, swapCoroutines, sysin, sysout, TRACE_GOTO
-
Constructor Details
-
RTS_CatchingErrors
Create a new _CatchingErrors instance.- Parameters:
staticLink
- the static link
-
-
Method Details
-
_onError_0
Default virtual match for procedure onError.- Returns:
- nothing
- Throws:
RTS_SimulaRuntimeError
- always
-
_onError
This method is called when a RuntimeException occur.- Parameters:
e
- a RuntimeExceptionmatch
- virtual match procedure
-