简体   繁体   English

未经检查的异常

[英]Unchecked exception

I try to Create a custom unchecked exception class called InvalidDateException. 我尝试创建一个名为InvalidDateException的自定义未经检查的异常类。 This exception class must include a constructor that takes a String as an argument. 此异常类必须包含一个将String作为参数的构造函数。 But I wonder is my code is custom unchecked exception or not. 但是我想知道我的代码是否是自定义的未经检查的异常。

class InvalidDateException extends RuntimeException
{
      //Parameterless Constructor
      public WordContainsException() {}  

      //Constructor that accepts a message
      public InvalidDateException(String message)
      {
         super(message);
      }
 }

Since your class extends Exception , it's a checked exception. 由于您的类扩展了Exception ,因此它是一个已检查的异常。 If you want to create an unchecked exception, you should extend RuntimeException . 如果要创建未经检查的异常,则应扩展RuntimeException

是的,您的Exception类是未经检查的异常类,因为您已经使用RuntimeException进行了扩展。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM