Java.lang.Throwable Class

Java.lang.Throwable Class

Introduction

The java.lang.Throwable class is the superclass of all errors and exceptions in the Java language. Only objects that are instances of this class (or one of its subclasses) are thrown by the Java Virtual Machine or can be thrown by the Java throw statement.

Class declaration

Following is the declaration for java.lang.Throwable class:

public class Throwable
   extends Object
      implements Serializable

Class constructors

S.N.Constructor & Description
1Throwable()This constructs a new throwable with null as its detail message.
2Throwable(String message)This constructs a new throwable with the specified detail message.
3Throwable(String message, Throwable cause)This constructs a new throwable with the specified detail message and cause.
4Throwable(Throwable cause)This constructs a new throwable with the specified cause and a detail message of (cause==null ? null : cause.toString()) (which typically contains the class and detail message of cause).

Class methods

S.N.Method & Description
1Throwable fillInStackTrace()

This method fills in the execution stack trace.

2Throwable getCause()

This method returns the cause of this throwable or null if the cause is nonexistent or unknown.

3String getLocalizedMessage()

This method creates a localized description of this throwable.

4String getMessage()

This method returns the detail message string of this throwable.

5StackTraceElement[] getStackTrace()

This method provides programmatic access to the stack trace information printed by printStackTrace().

6Throwable initCause(Throwable cause)

This method initializes the cause of this throwable to the specified value.

7void printStackTrace()

This method prints this throwable and its backtrace to the standard error stream.

8void printStackTrace(PrintStream s)

This method prints this throwable and its backtrace to the specified print stream.

9void printStackTrace(PrintWriter s)

This method prints this throwable and its backtrace to the specified print writer.

10void setStackTrace(StackTraceElement[] stackTrace)

This method sets the stack trace elements that will be returned by getStackTrace() and printed by printStackTrace() and related methods.

11String toString()

This method returns a short description of this throwable.

Methods inherited

This class inherits methods from the following classes:

  • java.lang.Object

Was this article helpful?

Related Articles

Leave A Comment?

You must be logged in to post a comment.