4
  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?

1

4 Answers 4

3

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

Sign up to request clarification or add additional context in comments.

Comments

1

Exceptions are checked unless they inherit from RuntimeException or Error

Comments

1

If your class extends Exception it can throw checked exceptions.

If your class extends Error or RuntimeException it can throw unchecked exceptions.

enter image description here

Comments

0

If you create class that extends Exception it would be checked. You can't specify RuntimeException as checked since it is unchecked exception

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.