📄 myexception2.java
字号:
package chapter14;
class Exception_my2 extends Exception {
private int num;
Exception_my2(int a) {
num = a;
}
public String toString() {
return "MyException[" + num + "]";
}
}
public class MyException2 {
static void compute(int a) throws Exception_my2 {
System.out.println("Called compute(" + a + ")");
if (a > 10) {
System.out.println("程序运行不正常");
throw new Exception_my2(a);
}
System.out.println("程序正常运行");
}
public static void main(String args[]) {
try {
compute(1);
System.out.println("------------------");
compute(20);
} catch (Exception_my2 e) {
System.out.println("捕获异常 " + e);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -