Java Exceptions are hierarchical and achieved by inheritance
to categorize different types of exceptions.
Throwable
is the parent class of Java Exceptions Hierarchy and it has two child
classes – Error
and Exception
.
Exceptions are further divided into two types checked
exceptions and unchecked exception.
Errors are exceptional scenarios that are out of scope of application and it’s not possible to anticipate and recover from them, for example hardware failure, JVM crash or out of memory error.
Checked Exceptions are exceptional scenarios that
we can anticipate in a program and try to recover from it, for
example FileNotFoundException. We should catch this exception and
provide useful message to user and log it properly for debugging
purpose. Exception
is the parent class
of all Checked Exceptions.
Unchecked Exceptions are caused by bad
programming, for example trying to retrieve an element from the
Array. We should check the length of array first before trying to
retrieve the element otherwise it might throw
ArrayIndexOutOfBoundException
at
runtime. RuntimeException
is the parent
class of all runtime exceptions.
Core Java Interview Questions
Object Oriented Programming(OOP) Questions and Answers
Collections Interview Questions
Java Exceptions Interview Questions
Java Threads Interview Questions
Collection framework in java interview questions
oops concepts with example in java
Java Serialization Interview Questions
Top 20 Core Java Interview Questions with Answers
String Interview Question in java With Example
synchronization interview questions
Java Reflection Interview question
Java Executor Framework (JDK 1.5) Interview Questions
JDK 1.7 interview Questations and Answers
Java I/O interview question with example