Thursday, March 12, 2009

What are Checked and Un-Checked Exceptions? Explain. (CoreJava)

Question :What are Checked and Un-Checked Exceptions? Explain. (CoreJava)
Answer :Throwable extends Object (checked)
Exception extends Throwable (checked)
RuntimeException extends Exception (un-checked)
Error extends Throwable (un-checked)
So anything that extends Throwable or Exception (except
RuntimeException) will be checked. Anything that extends Error or
RuntimeException will be un-checked
Checked exceptions are problems that arise in correct code and may be
due to technical problems such as IO problems or user mistakes such as
opening a socket when the remote machine does not exist. Because these
problems can occur at anytime, say due to network outage, you must have
code that can handle and recover from these. In fact, the Java compiler
checks that you have trapped them, hence checked exceptions.
Runtime exceptions are typically bugs in the program. Errors are severe
problems such as out of memory and sufficiently rare, that you are notrequired to handle them as they are usually unrecoverable.

No comments: