myexception2.java
来自「JAVA编程思想源代码 值得一下 很难找的」· Java 代码 · 共 38 行
JAVA
38 行
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 + =
减小字号Ctrl + -
显示快捷键?