Tutorials

Java Exception Handling


Exception Hierarchy


All the exception classes are derived from the class Exception.

Exception class is itself subclass of Throwable

Throwable is derived from Object.

 

Object class is the base class of all the classes in java

Let's have a look at the below given diagram representing hierarchy of Exception classes in java. 

Java Exception Hierarchy by tutorialsinhand.com

 

Form the diagram given above we can see two classes being derived from Throwable:

 

Error 

Error represents any unusual situation which is not a result of your written code.

It generally indicates those condition which cannot be recovered by making changes in your code base so you should not be bothered about handling them.

Errors are not Exception as they are not derived from class Exception.

 

Example

  • JVM  running out of memory during program execution is an example of the Error.
  • StackOverflowError occuring during program execution is an example of the Error.

 

Exception

Exception represents any unusual behaviour that disturbs the normal flow of the program.

Exception can be a Runtime exception or any other exception. 

 

Example

  • ArithmeticException
  • ArrayIndexOutOfBound
  • FileNotFound

 

To read more about Exception visit this chapter : Introduction to Exception 

 

Throwable provides lots of methods that helps its sub-classes to handle exception in better way.

For example you can you use printStackTrace() method to check from where the Exception actually originated.

 

 



Please Share this page
Views : 154
Like every other website we use cookies. By using our site you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service. Learn more Got it!