Facebook Page Twitter Page LinkedIn Page
× Java.lang Package Classes


Java Throwable Class

Java.lang package provides a Throwable class which 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. Similarly, only this class or one of its subclasses can be the argument type in a catch clause.

Class declaration

The declaration of java.lang.Throwable class is:

public class Throwable
  extends Object
    implements Serializable

Class Constructors

S.NConstructors & Description
1. Throwable()
Constructs a new throwable with null as its detail message.
2. Throwable(String message)
Constructs a new throwable with the specified detail message.
3. Throwable(String message, Throwable cause)
Constructs a new throwable with the specified detail message and cause.
4. protected Throwable(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace)
Constructs a new throwable with the specified detail message, cause, suppression enabled or disabled, and writable stack trace enabled or disabled.
5. Throwable(Throwable cause)
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).

java.lang.Throwable Methods

The java.lang.Throwable class has a number of methods which are listed below:

Member Methods

S.NMethods & Description
1. String getMessage()
Returns the detail message string of this throwable.
2. void printStackTrace()
Prints this throwable and its backtrace to the standard error stream.
3. void printStackTrace(PrintStream s)
Prints this throwable and its backtrace to the specified print stream.
4. void printStackTrace(PrintWriter s)
Prints this throwable and its backtrace to the specified print writer.
5. String toString()
Returns a short description of this throwable.

Methods inherited

This class inherits the methods of following class:

  • java.lang.Object