一、第一种定义方式,继承Exception类 public class MyFirstException extends Exception { public MyFirstException() { super(); } public MyFirstException(String msg) { super(msg); } public MyFirstException(String msg, Throwable cause) { super(msg, cause); } public MyFirstException(Throwable cause) { super(cause); } //自定义异常类的主要作用是区分异常发生的位置,当用户遇到 | |
二、 第二种定义方式:继承Throwable 类 public class MySecondException extends Throwable { public MySecondException() { super(); } public MySecondException(String msg) { super(msg); } public MySecondException(String msg, Throwable cause) { super(msg, cause); } public MySecondException(Throwable cause) { super(cause); } } |
自定义异常类
最新推荐文章于 2024-08-19 22:45:00 发布