Reputation: 17654
In Java, when I decide to throw an exception, is it possible to define this Exception as not having to be handled?
Thanks :-)
(I am on Java 7)
Upvotes: 3
Views: 64
Reputation: 7804
It can be achieved by throwing a unchecked exception. RuntimeException are unchecked exception which the calling program need not handle. Any sub-class like ClassCastException etc, are derived from RuntimeException and you need not worry about handling them.
Upvotes: 1
Reputation: 42849
Any Exception
that is a child type of RuntimeException
is not required to be handled. This is called an unchecked exception.
That said, you can still choose to handle it, should you feel that it is necessary.
Upvotes: 8