简体   繁体   English

声明不需要处理的异常?

[英]Declare an exception not having to be handled?

In Java, when I decide to throw an exception, is it possible to define this Exception as not having to be handled? 在Java中,当我决定抛出异常时,是否可以将此异常定义为不必处理?

Thanks :-) 谢谢 :-)

(I am on Java 7) (我在Java 7上)

Any Exception that is a child type of RuntimeException is not required to be handled. 不需要处理任何子类型的RuntimeException Exception This is called an unchecked exception. 这称为未经检查的异常。

That said, you can still choose to handle it, should you feel that it is necessary. 也就是说,如果您认为有必要,您仍然可以选择处理它。

It can be achieved by throwing a unchecked exception. 它可以通过抛出未经检查的异常来实现 RuntimeException are unchecked exception which the calling program need not handle. RuntimeException是未经检查的异常,调用程序无需处理该异常。 Any sub-class like ClassCastException etc, are derived from RuntimeException and you need not worry about handling them. 任何类ClassCastException等子类都是从RuntimeException派生的,您无需担心处理它们。

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

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