d语言的异常
参考自d程序设计语言---我的博客http://my.oschina.net/u/218155/blog?fromerr=SwOkb7Sw fllow me
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");
}
}