?? testthrowexception.java
字號:
class MyException extends Exception { //自定義的異常類
String NewExceptionObject;
public MyException() { //構造函數
this.NewExceptionObject="";
}
public MyException(String s) { //構造函數
this.NewExceptionObject=s;
}
String ShowExceptionInfo() { //返回接收到的異常信息
return this.NewExceptionObject;
}
}
public class TestThrowException {
public static void main(String[] args) {
try {
throw new MyException("這是一個自行拋出的異常!"); //拋出異常
}
catch(MyException e) {
System.out.println("MyException類:");
System.out.println("已經捕捉到拋出的異常對象!");
System.out.println("異常信息:"+e.ShowExceptionInfo());
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -