?? ex8(2).java
字號:
// exceptions/Ex8.java
// TIJ4 Chapter Exceptions, Exercise 8, page 458
/* Write a class with a method that throws an exception of the type created
* in Exercise 4. Try compiling it without an exception specification to see
* what the compiler says. Add the appropriate exception specification. Try
* out your class and its exception inside a try-catch clause.
*/
class Exception4 extends Exception {
private String msg;
Exception4(String msg) {
super(msg);
System.out.println("Exception4()");
this.msg = msg;
}
protected void showS() {
System.out.println("Message from Exception4: " + msg);
}
}
class Test8 {
public static void f() throws Exception4 {
System.out.println("f()");
throw new Exception4("Ouch from f()");
}
}
public class Ex8 {
public static void main(String[] args) {
try {
Test8 t = new Test8();
t.f();
} catch(Exception4 e) {
System.err.println("Caught Exception4");
e.printStackTrace();
e.showS();
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -