What are Checked and UnChecked Exception?The java.lang.Throwable class has two subclasses Error and Exception. There are two types of exceptions non runtime exceptions and runtime exceptions. Non runtime exceptions are called checked exceptions and the unchecked exceptions are runtime exceptions.
Runtime Exceptions occur when the code is not robust and non runtime exceptions occur due to the problems in environment, settings, etc. What is checked and unchecked exception? The exceptions that are not the sub classes of RuntimeException and its sub classes are called checked exceptions. A checked exception forces the developer to handle it. For example, IOException is a checked exception.
The exceptions that are the exceptions of RuntimeException and its sub classes are called unchecked exceptions. The class Error and its subclasses also are unchecked exceptions. An unchecked exception does not force the developer to handle it, either by catch block or by throws clauses. The developer may not predict these exceptions to handle. For example, ArrayIndexOutOfBoundsException is an unchecked exception.
|