//自定义异常类标签:自定义,int,MyException,System,异常,public,out From: https://www.cnblogs.com/huangjiangfei/p/17983957
public class MyException extends Exception{
//传递数字》10
private int detail;
public MyException(int a) {
this.detail = a;
}
@Override
public String toString() {
return "MyException{" + detail + '}';
}
}
=================================================
public class Test1 {
static void test(int a) throws MyException {
System.out.println("传递的参数为"+a);
if(a>10){
throw new MyException(a);
}
System.out.println("Ok");
}
public static void main(String[] args) {
try {
test(1);//alt+enter 自动提示错误
} catch (MyException e) {
System.out.println("MyException=>"+e);
}
}
}