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

Line 886:
Caught a U0 with message: 'This is the U0 exception'
This is the U1 exception
</pre>
=={{header|Elena}}==
ELENA 3.2.1 :
<lang elena>import extensions.
 
class U0 :: Exception.
 
class U1 :: Exception.
 
singleton Exceptions
{
static int i.
bar
<= baz.
 
baz
[
if (i == 0)
[
U0 new; raise
];
[
U1 new; raise
]
]
foo
[
i := 0.
while (i < 2)
[
try($self bar)
{
on(U0 e)
[
console printLine("U0 Caught").
]
}.
i += 1.
]
]
}
 
program =
[
Exceptions foo.
].</lang>
{{out}}
<pre>
U0 Caught
mytest'U1#class
Call stack:
system'Exception#class.new$system'LiteralValue[1]:exceptions.l(124)
system'Exception#class.new[0]:exceptions.l(128)
mytest'Exceptions.baz[0]:test.l(21)
mytest'Exceptions.bar[0]:test.l(12)
mytest'Exceptions.foo[0]:test.l(30)
mytest'program.eval[0]:test.l(45)
system'#inline1AB.start[1]:win32_app.l(35)
system'startUp(1)
</pre>
 
Anonymous user