Anonymous user
Exceptions/Catch an exception thrown in a nested call: Difference between revisions
Exceptions/Catch an exception thrown in a nested call (view source)
Revision as of 11:10, 3 November 2013
, 10 years ago→{{header|Lasso}}: Added stdout to code and output to example.
(→{{header|Lasso}}: Output?) |
(→{{header|Lasso}}: Added stdout to code and output to example.) |
||
Line 1,267:
=={{header|Lasso}}==
Lasso currently does not currently have a try mechanic — but we can easily add one like so.
Line 1,277 ⟶ 1,276:
handle => {
// Only relay error if it's not the specified exception
if(#error
if(#error->get(2) == #exception) => {
stdoutnl('Handled exception: '+#error->get(2))
else
stdoutnl('Throwing exception: '+#error->get(2))
fail(:#error)
}
}
}
protect => {
Line 1,288 ⟶ 1,294:
define foo => {
stdoutnl('foo')
try('U0') => { bar }
try('U0') => { bar }
Line 1,293 ⟶ 1,300:
define bar => {
stdoutnl('- bar')
baz()
}
define baz => {
stdoutnl(' - baz')
var(bazzed) ? fail('U1') | $bazzed = true
fail('U0')
}</lang>
Output:
<lang Lasso>foo
- bar
- baz
Handled exception: U0
- bar
- baz
Throwing exception: U1</lang>
Error Stack:
13:2 error.lasso
38:19 Debugger
33:5 Debugger
28:20 Debugger
21:9 Debugger
18:9 Debugger
6:5 Debugger</lang>
=={{header|Lua}}==
|