Home‎ > ‎Applied Core Java‎ > ‎

Exception Handling

An exception is an event or abnormal condition, which occurs during the execution of a program that disrupts the normal flow of the program's instructions.

There are two ty
pes of abnormal conditions




Exception :
Abnormal conditions those can be handled and program can execute alternate flow of actions is called Exception. For example: ArithmeticException, NullPointerException, FileNotFoundException etc.

Assumed that you got a dog before you in a Jungle then you can run away, that is called Exception.





Error : Abnormal conditions those can NOT be handled and will terminate program is called Error. For example : JVMError, MemoryStackOverFlow, etc.                                                    

Assumed that you got a Tiger before you in a Jungle then you can not do anything, everything will be done by tiger is called Error.



Fig 1 : Exception class Hierarchy
java.lang.Throwable is the root exception class. It has two child java.lang.Exception and java.lang.Error.  All exception classes are child of java.lang.Exception class whereas all Error classes are child of java.lang.Error class.

Different types of Exceptions:-

[1] Checked Exceptions

These are the exceptional conditions those may occur due to environmental conditions like network disconnected, file not found etc. These are not programming mistakes.  Checked exceptions are mandatory to handle using try-catch block.  Check exception may be propagated to calling methods using throws keyword.

[2] Unchecked Exceptions

These exceptions does not required mandatory exception handling code.  Error and its child, RuntimeException and its child classes are unchecked exceptions.

<<Previous | Next>>