Checked Exception is compile time or runtime? [closed]

不羁的心 提交于 2019-12-19 12:20:14

问题


I read about Checked exception that it is checked by compiler , but its runtime only.

Is it correct?

If it is correct then how?


回答1:


Checked exceptions are checked at compile time to ensure you are handling them, either by catching them or declaring the containing method throws the exception.

At runtime, there is no distinction between checked and unchecked exceptions: they are treated identically by the JVM. So "checked-ness" is purely a compile-time concept.




回答2:


Runtime exceptions are not checked exceptions. Checked exceptions are the class Exception and all subclasses except for RuntimeException.

Checked exceptions need to be either handled in your code or declared in the method's signature otherwise your code won't compile. Runtime exceptions do not need to be handled or declared.



来源:https://stackoverflow.com/questions/50549579/checked-exception-is-compile-time-or-runtime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!