Exceptions/Catch an exception thrown in a nested call: Difference between revisions
Content added Content deleted
(Added Erlang) |
|||
Line 1,265: | Line 1,265: | ||
<pre>caught exception U0 |
<pre>caught exception U0 |
||
uncaught exception: U1</pre> |
uncaught exception: U1</pre> |
||
=={{header|Lasso}}== |
|||
Lasso currently does not currently have a try mechanic — but we can easily add one like so. |
|||
<lang Lasso>define try(exception) => { |
|||
local( |
|||
gb = givenblock, |
|||
error |
|||
) |
|||
handle => { |
|||
// Only relay error if it's not the specified exception |
|||
#error && #error->get(2) != #exception ? fail(:#error) |
|||
} |
|||
protect => { |
|||
handle_error => { |
|||
#error = (:error_code,error_msg,error_stack) |
|||
} |
|||
#gb() |
|||
} |
|||
} |
|||
define foo => { |
|||
try('U0') => { bar } |
|||
try('U0') => { bar } |
|||
} |
|||
define bar => { |
|||
baz() |
|||
} |
|||
define baz => { |
|||
var(bazzed) ? fail('U1') | $bazzed = true |
|||
fail('U0') |
|||
} |
|||
foo()</lang> |
|||
=={{header|Lua}}== |
=={{header|Lua}}== |