Topics Index

Exceptions >
Siva Nookala - 18 Mar 2016
Java throws two types of exceptions - one is Error and the other is Exception. Both the classes Error and Exception extend from a common super-class Throwable.

Any exception of type Exception can be handled by the user programs using the try-catch block as explained in Exception Handling In Java with Example Program. The RuntimeException class extends from Exception and any class which extends from RuntimeException is considered as unchecked exception. Any exception which extends from Exception class is considered as checked exception. The difference is explained in Checked Exception Vs Unchecked Exception In Java.
The other type of exceptions are Error. These define exceptions that are not expected to be caught under normal circumstances by the user program. Exceptions of type Error are used by the Java run-time system to indicate errors having to do with the run-time environment. StackOverflowError is an example of Error. This is thrown when we recursively call the same method and it exceeds the number of method calls. OutOfMemoryError is also an Error and this is thrown by the run-time system, when it does not have sufficient memory to execute the program.

The hierarchy of Throwable, Exception, RuntimeException and Error is shown below. Error-exception-throwable-hierarchy

Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App