Showing posts with label Unchecked Exception. Show all posts
Showing posts with label Unchecked Exception. Show all posts

Wednesday 11 February 2015

Checked & Unchecked Exception

1) Checked Exception is required to be handled by compile time while Unchecked Exception doesn't.
2) Checked Exception is direct sub-Class of Exception while Unchecked Exception are of Runtime Exception.
3) Checked Exception represent scenario with higher failure rate while Unchecked Exception are mostly programming mistakes.

Here are few examples of Unchecked Exception in Java library:

  • NullPointerException
  • ArrayIndexOutOfBound
  • IllegalArgumentException
  • IllegalStateException


Summary:
1. Both Checked and Unchecked Exception are handled using keyword try, catch and finally.
2. In terms of Functionality Checked and Unchecked Exception are same.
3. Checked Exception handling verified during compile time.
4. Unchecked Exception are mostly programming errors
5. JDK7 provides improved Exception handling code with catching multiple Exception in one catch block and reduce amount of boiler plate code required for exception handling in Java.