I need some help in uncluttering my mind about exceptions. Could some one explain in plain english what is the difference between checked and a unchecked exception. I have gone thru few examples and tech. documentation and cluttered my view. TIA
Originally posted by Rahul K: Could some one explain in plain english what is the difference between checked and a unchecked exception.
Quick answer: an unchecked exception is any exception that extends RuntimeException. Errors could also fall into the realm of unchecked exceptions, although they're slightly different than a normal exception (at least semantically). Long Answer: A Checked exception is an exception that the compiler will check for. The compiler ensures that you have provided a handler for that exception (even if it's empty) or it issues an error when you try to compile your code. For example, if you invoke the method Thread.sleep(), you must either catch the InterruptedException that it can throw (as this is a checked exception) or decalre that this method throws it. In such a case, the invoking method would be required to deal with the exception in the same way. An unchecked exception is something that the compiler doesn't check for. An ArrayIndexOutOfBoundsException would be such an exception. Whenever you use the  operator to get a value from an array, the compiler doesn't require you to handle the ArrayIndexOutOfBoundsException that could occur because this is a run-time exception. It is still possible to catch a run-time exception, although it is not required. If you fail to do so, however, your application will terminate when/if such an exception occurs. Simply put, checked exceptions are exceptions the compiler checks for and unchecked exceptions are exceptions that the compiler doesn't check for. Hope that helps, Corey