C / C++的和Java的异常机制[2]
关键字: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");
}
}
}
原文转自:http://www.ltesting.net