Exceptions/Catch an exception thrown in a nested call: Difference between revisions

m
→‎{{header|REXX}}: added/changed comments in the REXX section header.
m (→‎{{header|REXX}}: removed OVERFLOW from PRE html tag.)
m (→‎{{header|REXX}}: added/changed comments in the REXX section header.)
Line 2,035:
 
=={{header|REXX}}==
While the REXX language doesn't have a ''throw'' capability ''pe se'', it does have the ability to catch exceptions (by label).
<br>This type of exception handling (in REXX) has its limitation &nbsp;
it does have the ability to catch exceptions (by label).
(the label is localknown global to the program, not external subroutines).
<br>This type of exception handling (in REXX) has its limitation
(the label is local to the program, not external subroutines).
<lang rexx>/*REXX program to create two exceptions & demonstrate how to handle them*/
call foo /*invoke the FOO function. */
say 'mainline program is done.' /*indicate that Elroy was here. */
exit /*stick a fork in it, we're done.*/
 
/*──────────────────────────────────FOO function────────────────────────*/
foo: call bar; call bar /*invoke BAR function twice. */
Line 2,049 ⟶ 2,047:
U0: say 'exception U0 caught in FOO' /*handle the U0 exception. */
return -2 /*return to the invoker. */
 
/*──────────────────────────────────BAR function────────────────────────*/
bar: call baz /*have BAR invoke BAZ function. */
return 0 /*return a zero to invoker. */
 
/*──────────────────────────────────BAZ function────────────────────────*/
baz: if symbol('BAZ#')=='LIT' then baz#=0 /*initialize BAZ invocation#*/
Line 2,059 ⟶ 2,055:
if baz#==1 then signal U0 /*if first invocation, raise U0 */
if baz#==2 then signal U1 /* " second " " U1 */
return 0 /*return a 0 (zero) to invoker. */
U0: return -1 /*handle exception[↓] this U0 ifsub notis caughtignored.*/
U1U0: return -1 /*handle exception if " " " " " not caught.*/</lang>
U1: return -1 /* " " " " " */</lang>
{{out}}
<pre>