自定义的异常类
程序员文章站
2024-03-20 18:20:22
...
自定义的异常类
package com.jin.www;
public class MyException extends Exception{
private int detail;
public MyException(int a) {
this.detail=a;
}
public String toString() {
return "MyException{"+detail+"}";
}
}
package com.jin.www;
public class Demo02 {
static void text(int a)throws MyException{
System.out.println("传递的参数为:"+a);
if(a>10) {
throw new MyException(a);
}
System.out.println("OK");
}
public static void main(String[] args) {
try {
text(11);
}catch(MyException e){
System.out.println("MyException=>"+e);
}
}
}
//输出:
//传递的参数为:11
//MyException=>MyException{11}
上一篇: node通过session登录验证
下一篇: 常见查找、排序算法的实现