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

→‎{{header|Lasso}}: Added stdout to code and output to example.
(→‎{{header|Lasso}}: Added stdout to code and output to example.)
Line 1,267:
 
=={{header|Lasso}}==
{{output?|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 && #error->get(2) !=> #exception ? fail(:#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:
 
foo()</lang Lasso>U1
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}}==
Anonymous user