Exceptions/Catch an exception thrown in a nested call: Difference between revisions
Content added Content deleted
m (→{{header|AutoHotkey}}: Minor indentation and casing edit) |
(added Ursala) |
||
Line 485: | Line 485: | ||
"foo" |
"foo" |
||
(file "exceptions.tcl" line 26)</pre> |
(file "exceptions.tcl" line 26)</pre> |
||
=={{header|Ursala}}== |
|||
Foo calls bar, and bar calls baz. Normal termination of bar is bypassed if |
|||
baz raises an exception. The exception is caught or not by foo. |
|||
<lang Ursala>#import std |
|||
baz = |
|||
~&?( |
|||
~&h?( |
|||
:/'baz succeeded with this input:', |
|||
<'baz threw a user-defined empty string exception','U1'>!%), |
|||
<'baz threw a user-defined empty file exception','U0'>!%) |
|||
bar = :/'bar received this result from normal termination of baz:'+ baz |
|||
#executable& |
|||
foo = |
|||
guard( |
|||
:/'foo received this result from normal termination of bar:'+ bar, |
|||
'U0'?=z/~& :/'foo caught an exception with this error message:')</lang> |
|||
Note that the definition of bar includes no conditional (?) or exception |
|||
handling operators, and is written without regard for any exceptions. |
|||
Here is an example bash session. |
|||
<pre> |
|||
$ echo "valid input" | foo |
|||
foo received this result from normal termination of bar: |
|||
bar received this result from normal termination of baz: |
|||
baz succeeded with this input: |
|||
valid input |
|||
$ foo < /dev/null |
|||
baz threw a user-defined empty file exception |
|||
U0 |
|||
$ echo "" | foo |
|||
foo caught an exception with this error message: |
|||
baz threw a user-defined empty string exception |
|||
U1</pre> |