Exceptions/Catch an exception thrown in a nested call: Difference between revisions
Content added Content deleted
(Fixed and updated D entry) |
(added Nemerle) |
||
Line 1,333: | Line 1,333: | ||
Error in ==> exceptionsCatchNestedCall at 29 |
Error in ==> exceptionsCatchNestedCall at 29 |
||
foo();</lang> |
foo();</lang> |
||
=={{header|Nemerle}}== |
|||
<lang Nemerle>using System; |
|||
using System.Console; |
|||
namespace NestedExceptions |
|||
{ |
|||
public class U0 : Exception |
|||
{ |
|||
public this() {base()} |
|||
} |
|||
public class U1 : Exception |
|||
{ |
|||
public this() {base()} |
|||
} |
|||
module NestedExceptions |
|||
{ |
|||
Foo () : void |
|||
{ |
|||
mutable call = 0; |
|||
repeat(2) { |
|||
try { |
|||
Bar(call); |
|||
} |
|||
catch { |
|||
|e is U0 => WriteLine("Exception U0 caught.") |
|||
} |
|||
finally { |
|||
call++; |
|||
} |
|||
} |
|||
} |
|||
Bar (call : int) : void |
|||
{ |
|||
Baz(call) |
|||
} |
|||
Baz (call : int) : void // throw U0() on first call, U1() on second |
|||
{ |
|||
unless (call > 0) throw U0(); |
|||
when (call > 0) throw U1(); |
|||
} |
|||
Main () : void |
|||
{ |
|||
Foo() |
|||
} |
|||
} |
|||
}</lang> |
|||
Output: |
|||
<pre>Exception U0 caught. |
|||
Unhandled Exception: NestedExceptions.U1: Exception of type 'NestedExceptions.U1' was thrown. |
|||
at NestedExceptions.NestedExceptions.Baz(Int32 call) |
|||
at NestedExceptions.NestedExceptions.Foo() |
|||
at NestedExceptions.NestedExceptions.Main()</pre> |
|||
=={{header|Objective-C}}== |
=={{header|Objective-C}}== |