Exceptions/Catch an exception thrown in a nested call: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: removed OVERFLOW from PRE html tag.) |
m (→{{header|REXX}}: added/changed comments in the REXX section header.) |
||
Line 2,035: | Line 2,035: | ||
=={{header|REXX}}== |
=={{header|REXX}}== |
||
While the REXX language doesn't have a ''throw'' capability ''pe se'', |
While the REXX language doesn't have a ''throw'' capability ''pe se'', it does have the ability to catch exceptions (by label). |
||
⚫ | |||
it does have the ability to catch exceptions (by label). |
|||
⚫ | |||
⚫ | |||
⚫ | |||
<lang rexx>/*REXX program to create two exceptions & demonstrate how to handle them*/ |
<lang rexx>/*REXX program to create two exceptions & demonstrate how to handle them*/ |
||
call foo /*invoke the FOO function. */ |
call foo /*invoke the FOO function. */ |
||
say 'mainline program is done.' /*indicate that Elroy was here. */ |
say 'mainline program is done.' /*indicate that Elroy was here. */ |
||
exit /*stick a fork in it, we're done.*/ |
exit /*stick a fork in it, we're done.*/ |
||
/*──────────────────────────────────FOO function────────────────────────*/ |
/*──────────────────────────────────FOO function────────────────────────*/ |
||
foo: call bar; call bar /*invoke BAR function twice. */ |
foo: call bar; call bar /*invoke BAR function twice. */ |
||
Line 2,049: | Line 2,047: | ||
U0: say 'exception U0 caught in FOO' /*handle the U0 exception. */ |
U0: say 'exception U0 caught in FOO' /*handle the U0 exception. */ |
||
return -2 /*return to the invoker. */ |
return -2 /*return to the invoker. */ |
||
/*──────────────────────────────────BAR function────────────────────────*/ |
/*──────────────────────────────────BAR function────────────────────────*/ |
||
bar: call baz /*have BAR invoke BAZ function. */ |
bar: call baz /*have BAR invoke BAZ function. */ |
||
return 0 /*return a zero to invoker. */ |
return 0 /*return a zero to invoker. */ |
||
/*──────────────────────────────────BAZ function────────────────────────*/ |
/*──────────────────────────────────BAZ function────────────────────────*/ |
||
baz: if symbol('BAZ#')=='LIT' then baz#=0 /*initialize BAZ invocation#*/ |
baz: if symbol('BAZ#')=='LIT' then baz#=0 /*initialize BAZ invocation#*/ |
||
Line 2,059: | Line 2,055: | ||
if baz#==1 then signal U0 /*if first invocation, raise U0 */ |
if baz#==1 then signal U0 /*if first invocation, raise U0 */ |
||
if baz#==2 then signal U1 /* " second " " U1 */ |
if baz#==2 then signal U1 /* " second " " U1 */ |
||
return 0 /*return a zero to invoker. |
return 0 /*return a 0 (zero) to invoker.*/ |
||
/* [↓] this U0 sub is ignored.*/ |
|||
U0: return -1 /*handle exception if not caught.*/ |
|||
U1: return -1 /* " " " " " */</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |