public class MyException extends Exception{ //继承Exception
private int detail;
public MyException(int a){
this.detail=a;
}
@Override
public String toString() {
return "MyException{" +
"detail=" + detail +
'}';
}
}
public class Application {
public static void main(String[] args) {
try {
new Application().test(110);
} catch (MyException e) {
System.out.println(e);
}
}
public void test(int a) throws MyException {
if(a>10){
throw new MyException(a);
}
System.out.println("ok");
}
}