Project

General

Profile

exception handling

Added by Sergey Durmanov 10 months ago

Let's say we have exceptions E1 and E2 and a procedure P that raises them.
We register the exceptions and call procedure P.

VAR e1: E1; e2: E2;
IF e1.Try() & e2.Try() THEN
  P();
ELSE
 ???
END;

1) How do we know which exception was raised? E1 or E2?
2) What happens if we forget to call e1.End, e2.End?
3) Does the order of calling End matter? (e1.End, e2.End) мы (e2.Endб e1.End)


Replies (1)

RE: exception handling - Added by Florian Negele 10 months ago

  1. Several exceptions should be registered using nested IF statements:
    IF e1.Try() THEN
        IF e2.Try() THEN
            P;
            e2.End;
        ELSE
            (* handle e2 *)
        ENDIF
        e1.End;
    ELSE
        (* handle e1 *)
    ENDIF
    
  2. When registering an exception, it is pushed onto a stack of registered exceptions. The End procedure pops the most current exception. If you forget to call this procedure, the stack becomes invalid.
  3. Yes, the order matters as only the most current exception is removed from the stack. Raising an exception automatically pops exceptions from the stack until an appropriate match is found.
    (1-1/1)