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:
1) goto a non-local label.
2) calling terminate_program or error
3) 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
-
Nested Class Summary
Nested classes/interfaces inherited from class simula.runtime.RTS_RTObject
RTS_RTObject.ForElt, RTS_RTObject.ForList, RTS_RTObject.ForListIterator, RTS_RTObject.OperationalState, RTS_RTObject.RTS_BOOLEAN_ARRAY, RTS_RTObject.RTS_BOUNDS, RTS_RTObject.RTS_CHARACTER_ARRAY, RTS_RTObject.RTS_INTEGER_ARRAY, RTS_RTObject.RTS_LABEL, RTS_RTObject.RTS_LONG_REAL_ARRAY, RTS_RTObject.RTS_NAME<T>, RTS_RTObject.RTS_REAL_ARRAY, RTS_RTObject.RTS_REALTYPE_ARRAY, RTS_RTObject.RTS_REF_ARRAY<T>, RTS_RTObject.RTS_TEXT_ARRAY, RTS_RTObject.SingleElt<T>, RTS_RTObject.SingleTValElt, RTS_RTObject.StepUntil, RTS_RTObject.UncaughtExceptionHandler, RTS_RTObject.WhileElt<T>, RTS_RTObject.WhileTValElt
-
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, NOTEXT
-
Constructor Summary
ConstructorDescriptionRTS_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
toString
Methods inherited from class simula.runtime.RTS_ENVIRONMENT
_char, _IPOW, _IS, abs, abs, abs, addepsilon, addepsilon, arccos, arcsin, arctan, arctan2, Char, clocktime, cos, cosh, cotan, cputime, datetime, decimalmark, DEFEXCEPTION, digit, discrete, draw, edfix, edit, edit, edit, edit, edit, edtime, entier, Erlang, error, exp, getIntInfo, getTextInfo, giveIntInfo, giveTextInfo, hash, histd, histo, isochar, isorank, letter, linear, ln, loadChar, log10, lowcase, lowerbound, lowten, max, max, max, max, max, min, min, min, min, min, mod, negexp, normal, Poisson, printStaticChain, printThreadList, randint, rank, rem, rts_utility, sign, simulaid, sin, sinh, sqrt, storeChar, subepsilon, subepsilon, tan, tanh, uniform, upcase, upperbound, waitSomeTime
Methods inherited from class simula.runtime.RTS_RTObject
_ASGSTR, _ASGTXT, _GOTO, _JUMPTABLE, _JUMPTABLE, _LABEL, _PRE_LABEL, _PRE_TABLE, _SIM_LABEL, _STM, _TXTREL_EQ, _TXTREL_GE, _TXTREL_GT, _TXTREL_LE, _TXTREL_LT, _TXTREL_NE, _VALUE, arrayValue, BBLK, blanks, BPRG, call, call, CONC, copy, detach, detach, detach, doubleValue, EBLK, edObjectAttributes, edObjectIdent, floatValue, getErrorMessage, intValue, isDetachUsed, isQPSystemBlock, objectTraceIdentifier, objectTraceIdentifier, objectValue, procValue, resume, resume, resume, swapCoroutines, sysin, sysout, terminate_program, TRACE_GOTO, TRF_EQ, TRF_NE
-
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
-