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

Added uBasic/4tH version
m (→‎{{header|langur}}: added curly braces to catch for clarity)
(Added uBasic/4tH version)
Line 3,190:
</pre>
 
=={{header|uBasic/4tH}}==
uBasic/4tH only captures an exception when a procedure is called by the function TRY(). TRY() returns zero when no exception was thrown. It returns the non-zero errorcode when an exception was thrown. RAISE can only throw user exceptions. If a procedure is called using the normal PROC keyword exceptions are not caught.
<syntaxhighlight lang="uBasic/4tH">u = 0 ' this is U0
v = 1 ' this is U1
 
Proc _foo ' call foo
End
 
_foo
For x = u To v ' throw U0 to U1
If x = u ' catch U0
If Try(_bar(x)) Then ' try to execute bar
Print "Function foo caught exception U0"
EndIf ' catch exception and write msg
Else ' don't catch other exceptions
Proc _bar(x)
EndIf
Next
Return
 
_bar
Param (1) ' bar takes a single parameter
Proc _baz(a@) ' bar calls baz
Return
 
_baz
Param (1) ' baz takes a single parameter
Raise a@ ' baz throws the exception
Return</syntaxhighlight>
{{Out}}
<pre>Function foo caught exception U0
 
Q Exception raised, 16092559880829058:136</pre>
=={{header|Ursala}}==
Foo calls bar, and bar calls baz. Normal termination of bar is bypassed
374

edits