3

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)

2
  • 2
    Did you do the java tutorial? Commented Mar 24, 2013 at 20:35
  • Be careful with runtime exceptions, though. Use them wisely. Commented Mar 24, 2013 at 20:36

2 Answers 2

8

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.

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

Comments

1

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.