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)
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)
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.
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.