World's most popular travel blog for travel bloggers.

Java Exception Hierarchy

, , No Comments

Exception Hierarchy

All exception classes are subtypes of the java.lang.Exception class. The exception class is a subclass of the Throwable class. Other than the exception class there is another subclass called Error which is derived from the Throwable class.
Errors are abnormal conditions that happen in case of severe failures, these are not handled by the Java programs. Errors are generated to indicate errors generated by the runtime environment. Example: JVM is out of memory. Normally, programs cannot recover from errors.
The Exception class has two main subclasses: IOException class and RuntimeException Class.


Following is a list of most common checked and unchecked Java's Built-in Exceptions.

Exceptions Methods

Following is the list of important methods available in the Throwable class.
Sr.No.Method & Description
1
public String getMessage()
Returns a detailed message about the exception that has occurred. This message is initialized in the Throwable constructor.
2
public Throwable getCause()
Returns the cause of the exception as represented by a Throwable object.
3
public String toString()
Returns the name of the class concatenated with the result of getMessage().
4
public void printStackTrace()
Prints the result of toString() along with the stack trace to System.err, the error output stream.
5
public StackTraceElement [] getStackTrace()
Returns an array containing each element on the stack trace. The element at index 0 represents the top of the call stack, and the last element in the array represents the method at the bottom of the call stack.
6
public Throwable fillInStackTrace()
Fills the stack trace of this Throwable object with the current stack trace, adding to any previous information in the stack trace.

0 comments:

Post a Comment

Let us know your responses and feedback