Module Simula

Class RTS_CatchingErrors

All Implemented Interfaces:
Runnable

public abstract class RTS_CatchingErrors extends RTS_CLASS
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
  • Constructor Details

    • RTS_CatchingErrors

      public RTS_CatchingErrors(RTS_RTObject staticLink)
      Create a new _CatchingErrors instance.
      Parameters:
      staticLink - the static link
  • Method Details

    • _onError_0

      public RTS_PRCQNT _onError_0()
      Default virtual match for procedure onError.
      Returns:
      nothing
      Throws:
      RTS_SimulaRuntimeError - always
    • _onError

      public void _onError(RuntimeException e, RTS_PRCQNT match)
      This method is called when a RuntimeException occur.
      Parameters:
      e - a RuntimeException
      match - virtual match procedure