java 用户定义的异常是已检查或未检查的异常

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10415747/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 00:57:50  来源:igfitidea点击:

User defined exception are checked or unchecked exceptions

java

提问by user1357722

In my web application created a User defined exception extends with Exception.Is it Checked or unchecked exception

在我的 web 应用程序中创建了一个用户定义的异常扩展与 Exception.Is Checked 或 unchecked 异常

public class InvalidDataException extends Exception{


        public InvalidDataException() {
        super();
        // TODO Auto-generated constructor stub
    }
    /**
     * @param arg0
     */
    public InvalidDataException(String message) {
        super(message);
        // TODO Auto-generated constructor stub
    }
}

回答by NPE

Only those exceptions that are subclasses of RuntimeExceptionare considered unchecked.

只有属于 的子类的那些异常才被RuntimeException视为未检查的

Yours isn't, and therefore is a checkedexception.

你的不是,因此是一个检查异常。

回答by Masarrat Siddiqui

It's a checked exception class. Any class which extends Exception class will be a user defined Checkedexception class. Where as any class which extends RuntimeException will be Uncheckedexception class.

这是一个检查异常类。任何扩展 Exception 类的类都将是用户定义的Checked异常类。任何扩展 RuntimeException 的类都将是Unchecked异常类。

回答by Surya

User Defined exceptions are checked exceptions because they are extended with Exception class which is super class for all the exceptions occured,where as unchecked exceptions are extended with run time Exceptions.

用户定义的异常是已检查的异常,因为它们扩展了 Exception 类,该类是所有发生的异常的超类,而未检查的异常则扩展为运行时异常。

回答by B_Ali_Code

THere are two classes call as partially checked exception.

有两个类作为部分检查异常调用。

1.) Exception class

1.) 异常类

2.) throwable class

2.) 可抛出类

It calls partially checked because some of their subclasses are Unchecked. So you have extended the Exception class then it's Checked exception

它调用部分检查,因为它们的一些子类是未检查的。所以你已经扩展了 Exception 类然后它是 Checked 异常

回答by Snicolas

You could have used IllegalArgumentException.

您可以使用IllegalArgumentException

This exception is unchecked whereas yours is checked as @duffymo & @aix commented.

这个异常没有被检查,而你的异常被检查为@duffymo & @aix 评论。