package com.guoba.exception;
/*
自定义异常类
*/
public class LiXuanException extends Exception{
private int detail;
public LiXuanException(int e){
this.detail = e;
}
@Override
public String toString() {
return "LiXuanException{" +
"detail=" + detail +
'}';
}
}
package com.guoba.exception;
public class test {
//可能会异常的方法
static void test(int e)throws LiXuanException{
System.out.println("传递的参数为"+e);
if (e>10){
throw new LiXuanException(e);//抛出
}
System.out.println("ok");
}
public static void main(String[] args) {
try {
test(11);
} catch (LiXuanException e) {
System.out.println("LixuanException=>"+e);
}
}
}