class Myself extends Exception {
int num=0;
Myself()
{
num++;
}
String show(){
return"自己的异常,编号:"+num;}
}
class My{
static void Disp(int n)throws Myself{
System.out.println("n"+n);
if(n<150)
{
System.out.println("不产生异常!");
return;
}
else{
throw new Myself();
}
}
public static void main(String args[]){
try{
Disp(50);
Disp(250);
}
catch(Myself e){
System.out.println("捕捉到的异常是:"+e.show());
}
}
}
创建自己的异常类
最新推荐文章于 2023-05-05 20:54:14 发布