Jump to content

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

no edit summary
No edit summary
No edit summary
Line 392:
Exception number 3 not handled.
Developer exception:</pre>
 
=={{header|Fantom}}==
 
<lang fantom>
const class U0 : Err
{
new make () : super ("U0") {}
}
 
const class U1 : Err
{
new make () : super ("U1") {}
}
 
class Main
{
Int bazCalls := 0
 
Void baz ()
{
bazCalls += 1
if (bazCalls == 1)
throw U0()
else
throw U1()
}
 
Void bar ()
{
baz ()
}
 
Void foo ()
{
2.times
{
try
{
bar ()
}
catch (U0 e)
{
echo ("Caught U0")
}
}
}
 
public static Void main ()
{
Main().foo
}
}
</lang>
 
Output:
 
<pre>
Caught U0
nestedexceptions_0::U1: U1
nestedexceptions_0::U1.<init> (nested-exceptions.fan)
nestedexceptions_0::U1.make (nested-exceptions.fan:9)
nestedexceptions_0::Main.baz (nested-exceptions.fan:22)
nestedexceptions_0::Main.bar (nested-exceptions.fan:27)
nestedexceptions_0::Main.foo (nested-exceptions.fan:36)
fan.sys.FanInt.times (FanInt.java:492)
nestedexceptions_0::Main.foo (nested-exceptions.fan:33)
nestedexceptions_0::Main.main (nested-exceptions.fan:47)
java.lang.reflect.Method.invoke (Method.java:597)
fan.sys.Method.invoke (Method.java:552)
fan.sys.Method$MethodFunc.callList (Method.java:198)
fan.sys.Method.callList (Method.java:138)
fanx.tools.Fan.callMain (Fan.java:135)
fanx.tools.Fan.executeFile (Fan.java:88)
fanx.tools.Fan.execute (Fan.java:34)
fanx.tools.Fan.run (Fan.java:250)
fanx.tools.Fan.main (Fan.java:288)
</pre>
 
The output shows the first exception is caught and handled. The second exception is not handled, and results in the program finishing and printing a stack trace.
 
=={{header|Haskell}}==
342

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.