Reputation: 1497
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.
If I create an exception class that extends RuntimeException
, can I specify that this class is checked?
Upvotes: 4
Views: 518
Reputation: 4516
If your class extends Exception it can throw checked exceptions.
If your class extends Error or RuntimeException it can throw unchecked exceptions.
Upvotes: 1
Reputation: 136112
Exceptions are checked unless they inherit from RuntimeException or Error
Upvotes: 1
Reputation: 350
If you create class that extends Exception it would be checked. You can't specify RuntimeException as checked since it is unchecked exception
Upvotes: 0
Reputation: 13853
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
Upvotes: 3