📄 extrafeatures.java
字号:
//: c10:ExtraFeatures.java
// Further embellishment of exception classes.
import com.bruceeckel.simpletest.*;
class MyException2 extends Exception {
public MyException2() {}
public MyException2(String msg) {
super(msg);
}
public MyException2(String msg, int x) {
super(msg);
i = x;
}
public int val() { return i; }
private int i;
}
public class ExtraFeatures {
public static void f() throws MyException2 {
System.out.println(
"Throwing MyException2 from f()");
throw new MyException2();
}
public static void g() throws MyException2 {
System.out.println(
"Throwing MyException2 from g()");
throw new MyException2("Originated in g()");
}
public static void h() throws MyException2 {
System.out.println(
"Throwing MyException2 from h()");
throw new MyException2(
"Originated in h()", 47);
}
public static void main(String[] args) {
SimpleTest monitor =
new SimpleTest("ExtraFeatures");
try {
f();
} catch(MyException2 e) {
e.printStackTrace(System.err);
}
try {
g();
} catch(MyException2 e) {
e.printStackTrace(System.err);
}
try {
h();
} catch(MyException2 e) {
e.printStackTrace(System.err);
System.err.println("e.val() = " + e.val());
}
monitor.expect(new String[] {
"Throwing MyException2 from f()",
"MyException2",
" at ExtraFeatures.f(Unknown Source)",
" at ExtraFeatures.main(Unknown Source)",
"Throwing MyException2 from g()",
"MyException2: Originated in g()",
" at ExtraFeatures.g(Unknown Source)",
" at ExtraFeatures.main(Unknown Source)",
"Throwing MyException2 from h()",
"MyException2: Originated in h()",
" at ExtraFeatures.h(Unknown Source)",
" at ExtraFeatures.main(Unknown Source)",
"e.val() = 47"
});
}
} ///:~
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -