自定义异常

package com.lsx.base;

public class MyException extends Exception {
private int detail;

public MyException(int detail) {
this.detail = detail;
}

@Override
public String toString() {
return "MyException{" +
"detail=" + detail +
'}';
}
}

class TestDemo {
public static void test(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 {
test(12);
} catch (MyException e) {
System.out.println("MyException==>" + e);
}
}
}
posted @   吾爱开发~  阅读(169)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示