import lombok.Data;
/**
* @author 01369526
*
*/
@Data
@SuppressWarnings("serial")
public class MyException extends RuntimeException implements Serializable{
private int errorcode;
public MyException(int errorcode,String message,Throwable throwable)
{
super(message,throwable);
this.errorcode=errorcode;
}
}
import java.util.ArrayList;
import java.util.List;
/**
* @author 01369526
*
*/
public class Test {
public void test(int a)
{
if (a==0) {
try {
List<Integer> list=new ArrayList<>();
list.add(666);
list.get(5);
} catch (Exception e) {
throw new MyException(666,"数组错误",e);
}
}}
}
*/
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
new Test().test(0);
}
catch (MyException exception) {
// TODO: handle exception
System.out.println(exception.getErrorcode()+"\n"+exception.getMessage()+"\n");
exception.printStackTrace();
}
}
}
输出:
666
数组错误
MyException(errorcode=666)
at exception.Test.test(Test.java: