[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: OOC Core Library



   Date: Thu, 30 Nov 95 10:27:30 EST
   From: Mike Griebling <grieblm@trt.allied.com>

   > [snip]

   Just tell me how to raise an exception and it can be done.

Here is how it's done by the Modula-2 DIS.  M2 allows to add an
exception handling part to the body of a procedure block.  If we
replace that by a mechanism to install a procedure as an exception
handler (similar to signal handlers in Unix), we may have a usable
concept.

-- mva

------------------------------------------------------------------------

From Modula-2 DIS 10514, June 1994:

DEFINITION MODULE EXCEPTIONS;

(* Provides facilities for raising user exceptions and for making
   enquiries concerning the current execution state. 
*)

TYPE 
  ExceptionSource;  (* values of this type are used within library
                       modules to identify the source of raise
                       exception *)
  ExceptionNumber = CARDINAL;

PROCEDURE AllocateSource (VAR newSource: ExceptionSource);
  (* Allocates a unique value of type ExceptionSource *)

PROCEDURE RAISE (source: ExceptionSource; number: ExceptionNumber;
                 message: ARRAY OF CHAR);
  (* Associates the given values of source, number and message with
     the current context and raises an exception.
   *)

PROCEDURE CurrentNumber (source: ExceptionSource): ExceptionNumber;
  (* If the current coroutine is in the exceptional execution state
     because of the raising of an exception from source, returns the
     corresponding number, and otherwise raises an exception. 
  *)

PROCEDURE GetMessage (VAR text: ARRAY OF CHAR);
  (* If the current coroutine is in the exceptional execution state,
     returns the possibly truncated string associated with the current
     context.  
     Otherwise, in normal execution state, returns the empty string.
  *)

PROCEDURE IsCurrentSource (source: ExceptionSource): BOOLEAN;
  (* If the current coroutine is in the exceptional execution state
     because of the raising of an exception from source, returns TRUE,
     and otherwise returns FALSE.
  *)

PROCEDURE IsExceptionalExecution (): BOOLEAN;
  (* If the current coroutine is in the exceptional execution state
     because of the raising of an exception, returns TRUE, otherwise
     returns FALSE. 
  *)

END EXCEPTIONS.

------------------------------------------------------------------------

Execption handlers are installed by providing a EXCEPT part in a
procedure or module block.  
Example:

  ...

  PROCEDURE TryFlying();
  BEGIN
    Fly
  EXCEPT
    (* statements in execeptional execution *)
    IF IsLibException() THEN
      CASE LibException() OF
      | brokenRubberBand:
        ReplaceRubberBand;
        RETRY  (* causes the normal block part to be retried, in the
                  state of normal execution *)
      ELSE
      END
    END
    (* Exceptional return re-raises the exeception *)
  END TryFlying;

  ...

------------------------------------------------------------------------