C / C++的和Java的异常机制[2]
来源:不详 责任编辑:栏目编辑 发表时间:2013-07-01 15:21 点击:次
关键字:C / C++ Java 异常机制一个简单例子:
public class MyException extends Exception
...{
MyException(String str)
...{
super(str);
}
}
public class MyTest
...{
public void f()throws MyException
...{
throw new MyException("f() exception");
}
}
public class Main
...{
public static void main(String[]args)
...{
try
...{
new MyTest().f();
}catch(MyException me)
...{
System.out.println(me);
}finally
...{System.out.println("finally");
}
}
}
public class MyException extends Exception
...{
MyException(String str)
...{
super(str);
}
}
public class MyTest
...{
public void f()throws MyException
...{
throw new MyException("f() exception");
}
}
public class Main
...{
public static void main(String[]args)
...{
try
...{
new MyTest().f();
}catch(MyException me)
...{
System.out.println(me);
}finally
...{System.out.println("finally");
}
}
}
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>