myexception.java
来自「这一些程序都是实验之用」· Java 代码 · 共 29 行
JAVA
29 行
public class MyException extends Exception{
int IdException;
public MyException(int IdException){
this.IdException=IdException;
}
public int getnum(){
return IdException;
}
}
class Test{
public void regist(int num)throws MyException{
if(num<0){
System.out.println(num);
throw new MyException(3);
}
System.out.println("注册人数为 "+num);
}
public void tester(){
try{regist(4);}catch(MyException e){
System.out.println("注册人数不能为负数请重新输入,异常ID: "+e.getnum());
}
}
public static void main(String args[]){
Test test=new Test();
test.tester();
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?