Java checked and unchecked exceptions

  • If I create an exception class that extends Exception, will my class be checked or dropped? I note that the subclass Exceptioncalled RuntimeExceptionis an unchecked exception, while all other subclasses of the β€œException” are marked with exceptions.

  • If I create an exception class that extends RuntimeException, can I indicate that this class is checked?

+4
source share
4 answers

1) Verified

2) No

If you added Exception -> checked

If you extend a RuntimeException -> unchecked

From the documentation:

{@code Exception} ,  * {@link RuntimeException}  *

enter image description here

+3

, RuntimeException Error

+1

If you create a class that extends Exception, it will be checked. You cannot throw a RuntimeException as noted, as this is an exception.

0
source

If your class extends Exception, it can throw checked exceptions.

If your class extends a RuntimeException error or exception, it may throw thrown exceptions.

enter image description here

0
source

All Articles