Exceptions: Difference between revisions

no edit summary
No edit summary
Line 282:
</cfcatch>
</cftry>
 
=={{header|D}}==
===Throw Exceptions===
<lang d>void test() {
throw new Exception("Sample Exception");
}</lang>
 
===Catch Exceptions===
<lang d>void test2() {
try test();
catch (Exception ex) { writefln(ex); throw ex; /* rethrow */ }
}</lang>
 
In debug mode, stack traces can be generated via an external package, but the standard library does not support it by default.
 
===Ways to implement finally===
<lang d>void test3() {
try test2();
finally writefln("test3 finally");
}</lang>
Or also with scope guards!
<lang d>void test4() {
scope(exit) writefln("Test4 done");
scope(failure) writefln("Test4 exited by exception");
scope(success) writefln("Test4 exited by return or function end");
test2();
}</lang>
 
=={{header|Factor}}==
Anonymous user