All About Class Throwable in Java



The throwable class is the superclass of all errors and exceptions in the java.Only objects which are instance of this class or one of it's subclass are thrown by the java virtual machine.It can also be thrown by java statement. So only this class or it's subclass can be the argument type in catch clause. A throwable object contains a snapshot of the execution stack of its thread at the time it was created.It can also contain a message string that gives more information about the error or exception.
The structure of the throwable class given below:


public class java.lang.Throwable extends java.lang.Object{
//constructors:
public Throwable();
//creates a new throwable object with no detail message. The stack trace is automatically filled in.
public Throwable(String message);
//creates a new throwable object with the detail message provided in the argument. The stack trace is automatically filled in.
//Methods:
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.
public String getMessage(); //returns the details message about the exception that has occurred. This message is initialized in the Throwable constructor.
public void printStackTrace();//prints the result of toString() along with the stack trace.
public void printStackTrace(PrintStream ps);//prints the result of toString() along with the stack trace to the Stream like System.err,the Error output stream
public String toString();//returns the name of the class concatenated with the result of getMessage().Short description of Throwable Object
public Throwable getCause();//returns the cause of the exception as represented by a Throwable Object
public stackTraceEmenet[] getStackTrace()//returns an error containing each element on the stack trace.The element at index-0 represents the top of call stack and the last element in the Array represents at the bottom of the call stack.
public void printStackTrace(PrintWriter ps)//prints the stack trace to the indicated print writer.
}
 
All About Class Throwable in Java All About Class Throwable in Java Reviewed by Animesh Chatterjee on September 18, 2018 Rating: 5

No comments:

Powered by Blogger.