异常
- try catch finally throw throws
- ctrl+alt+T
public class MyException extends Exception {
//传递数字>10
private int detail;
public MyException(int a) {
// super(message);
this.detail = a;
}
//异常的打印信息
@Override
public String toString() {
return "MyException{" +
"detail=" + detail +
'}';
}
}
public class Test {
//可能存在异常的方法
static void test(int b) throws MyException {
System.out.println("传递的参数为:");
if (b>10){
throw new MyException(b);
}
System.out.println("ok");
}
public static void main(String[] args) {
try {
test(17);
} catch (MyException e) {
System.out.println("MyException=>"+e);
}finally {
System.out.println("继续");
}
}