62,635
社区成员




class MyException extends Exception {
private int id;
public MyException(String message, int id){
super(message);
this.id = id;
}
public int getId(){
return id;
}
}
public class TestMyException{
public static void regist(int num) throws MyException{
if(num<0){
throw new MyException("num is errorous",3);
}
System.out.println("The number of registion is :"+num);
}
public static void main(String[] args) throws Exception{
try{
regist(-1);
}catch(MyException e){
System.out.println("The code of error is:"+e.getId());
//Thread.sleep(1000);
e.printStackTrace();
}
System.out.println("Operation is over");
}
}