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

Content added Content deleted
(→‎{{header|Lasso}}: Added stdout to code and output to example.)
Line 1,267: Line 1,267:


=={{header|Lasso}}==
=={{header|Lasso}}==
{{output?|Lasso}}
Lasso currently does not currently have a try mechanic — but we can easily add one like so.
Lasso currently does not currently have a try mechanic — but we can easily add one like so.


Line 1,277: Line 1,276:
handle => {
handle => {
// Only relay error if it's not the specified exception
// Only relay error if it's not the specified exception
#error && #error->get(2) != #exception ? fail(:#error)
if(#error) => {
if(#error->get(2) == #exception) => {
stdoutnl('Handled exception: '+#error->get(2))
else
stdoutnl('Throwing exception: '+#error->get(2))
fail(:#error)
}
}
}
}
protect => {
protect => {
Line 1,288: Line 1,294:


define foo => {
define foo => {
stdoutnl('foo')
try('U0') => { bar }
try('U0') => { bar }
try('U0') => { bar }
try('U0') => { bar }
Line 1,293: Line 1,300:


define bar => {
define bar => {
stdoutnl('- bar')
baz()
baz()
}
}


define baz => {
define baz => {
stdoutnl(' - baz')
var(bazzed) ? fail('U1') | $bazzed = true
var(bazzed) ? fail('U1') | $bazzed = true
fail('U0')
fail('U0')
}</lang>
}

Output:

<lang Lasso>foo
- bar
- baz
Handled exception: U0
- bar
- baz
Throwing exception: U1</lang>

Error Stack:


foo()</lang>
<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}}==
=={{header|Lua}}==