我喜欢创建Exception类,其名称表示注意和抛出特定于应用程序的问题.
为了定义它们,通常会定义一个新类,其超类是一些异常类型.
由于父Exception类中有多个常见的构造函数,通常子类看起来像这样:
package com.example.exception; /** * MyException is thrown when some application-level expectation is not met. */ public class MyException extends Exception { public MyException() { super(); } public MyException(String message) { super(message); } public MyException(Throwable cause) { super(cause); } public MyException(String message,Throwable cause) { super(message,cause); } }