d語言的異常fetch
參考自d程序設計語言---個人博客http://my.oschina.net/u/218155/blog?fromerr=SwOkb7Sw fllow methis
import std.stdio; import std.exception; class MyException:Exception{ this(string s){ super(s); } } void fun(){ throw new MyException("fun has Exception"); } nothrow int demult(int a, int b) { if(b == 0) return 0; return a/b; } void main() { try{ fun(); }catch(MyException myExp){ writeln("MyException"); }catch(Exception e2){ writeln("Exception"); }finally{ writeln("always run finally"); //throw new Exception("excpetion in finally "); } try{ demult(1,0); }catch(Exception e){ writeln("can't fetch rest data"); } scope(exit){ writeln("scope1"); } scope(exit){ writeln("scope2"); } }