Exceptions/Catch an exception thrown in a nested call: Difference between revisions
Content deleted Content added
Line 57:
is effectively bound to the '''file''' handle, hence different '''file''' events can be caught
by event handler associated to that particular '''file'''. Similarly the following example
has bound
c.f. [[Exceptions#ALGOL_68|ALGOL 68 Exceptions]] for more details.
<lang algol>MODE OBJ = STRUCT(
INT value,
STRUCT(
STRING message,
FLEX[0]STRING args,
PROC(REF OBJ)BOOL u0, u1
Line 69:
);
PROC on u0 = (REF OBJ self, PROC (REF OBJ) BOOL mended)VOID:
u0 OF exception OF self := mended;
PROC on u1 = (REF OBJ self, PROC (REF OBJ) BOOL mended)VOID:
u1 OF exception OF self := mended;
PRIO INIT = 1, RAISE = 1;
OP INIT = (REF OBJ self, INT value)REF OBJ: (
Line 85:
OP RAISE = (REF OBJ self, PROC (REF OBJ) BOOL mended)VOID:
IF NOT mended(self) THEN
put(stand error, (message OF exception OF self+" not caught - stop", new line));
stop
FI;
Line 109:
# PROC # baz := (REF OBJ i)VOID:
IF value OF i = 0 THEN
i RAISE u0 OF exception OF i
ELSE
i RAISE u1 OF exception OF i
FI;
foo</lang>
Output:▼
<pre>▼
Function foo caught exception u0▼
OBJ Exception not caught - stop▼
</pre>▼
Note: when an event occurs there are three possible responses.
# return '''false''' - in which case the default action takes place.
Line 124 ⟶ 129:
'''par''' clause, then all parallel the threads are terminated and the
program continues in the parent thread. <!-- example needed -->
▲Output:
▲<pre>
▲Function foo caught exception u0
▲OBJ Exception not caught - stop
▲</pre>
=={{header|C++}}==
|