/**
* <p>Title: 捕獲異常和實現自己的異常類</p>
* <p>Description: 通過繼承Exception類來實現自己的異常類
* <p>Copyright: Copyright (c)
* <p>Filename: </p>
* @version
*/
class MyException extends Exception {
public MyException() {}
public MyException(String msg) {
super(msg);
}
public MyException(String msg
super(msg);
i = x;
}
public int val() { return i; }
private int i;
}
public class DemoException {
/**
*<br>方法說明
*<br>輸入參數
*<br>返回類型
*/
public static void a() throws MyException {
System
throw new MyException();
}
/**
*<br>方法說明
*<br>輸入參數
*<br>返回類型
*/
public static void b() throws MyException {
System
throw new MyException(
}
/**
*<br>方法說明
*<br>輸入參數
*<br>返回類型
*/
public static void c() throws MyException {
System
throw new MyException(
}
public static void main(String[] args) {
try {
a();
} catch(MyException e) {
e
}
try {
b();
} catch(MyException e) {
e
}
try {
c();
} catch(MyException e) {
e
System
}
}
} //end
From:http://tw.wingwit.com/Article/program/Java/hx/201311/25709.html