简体   繁体   English

Customized Exception是选中还是未选中的Exception?

[英]Customized Exception is checked or unchecked Exception?

Whether the Customized Exception is Checked or Unchecked Exception? 定制异常是检查异常还是未检查异常? How? 怎么样?

If you do like this: 如果您这样做:

public class CustomException extends Exception

then your CustomException is checked exception 然后您的CustomException被检查的异常

If you do like this: 如果您这样做:

public class CustomException extends RuntimeException

then your CustomException is unchecked exception 那么您的CustomException是未经检查的异常

If an exception inherits from RuntimeException then it is unchecked. 如果异常继承自RuntimeException则将其取消选中。 Otherwise it is checked. 否则将被检查。

It depends on what it inherits. 这取决于它所继承的东西。 If your custom exception is a subclass of RuntimeException then it is unchecked exception. 如果您的自定义异常是RuntimeException的子类,则它是未经检查的异常。

And if your custom exception extends Exception class then it is checked exception. 并且,如果您的自定义异常扩展了Exception类,则将其检查为异常。

See the Differences between Runtime/Checked/Unchecked/Error/Exception for more details 有关更多详细信息,请参见运行时/已检查/未检查/错误/异常之间差异。

depends on inheritance. 取决于继承。 if it inherits from RuntimeException it is unchecked. 如果它继承自RuntimeException,则未经检查。 Otherwise it is checked 否则检查

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

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