Search code examples
javaexceptioncheckedunchecked

Java checked and unchecked exceptions


  1. If I create an exception class that extends Exception, will my class be checked or unchecked? I note that the subclass of Exception called RuntimeException is an unchecked exception whereas all other subclasses of 'Exception' are checked exceptions.

  2. If I create an exception class that extends RuntimeException, can I specify that this class is checked?


Solution

  • 1) Checked

    2) No

    If you extend Exception -> checked

    If you extend RuntimeException -> unchecked

    From documentation:

    The class {@code Exception} and any subclasses that are not also * subclasses of {@link RuntimeException} are checked * exceptions

    enter image description here