首页 > 学院 > 开发设计 > 正文

自定义异常的简单写法

2019-11-11 03:33:11
字体:
来源:转载
供稿:网友

public class MyException extends Exception {

public MyException() {};public MyException(String msg) {super(msg);}

}

public class Test {public static void f() throws MyException {System.out.PRintln("f");throw new MyException();}public static void g() throws MyException {System.out.println("g");throw new MyException("g");}public static void main(String[] args) {try {f();} catch (MyException e) {// e.printStackTrace(System.out);e.printStackTrace();}try {g();} catch (MyException e) {e.printStackTrace(System.out);}}}


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表