Package java.lang

Class Throwable

  • All Implemented Interfaces:
    Serializable, Modified
    Direct Known Subclasses:
    Error, Exception

    public class Throwable
    extends Object
    implements Serializable, Modified
    The superclass of all classes which can be thrown by the VM. The two direct subclasses are recoverable exceptions (Exception) and unrecoverable errors (Error). This class provides common methods for accessing a string message which provides extra information about the circumstances in which the Throwable was created (basically an error message in most cases), and for saving a stack trace (that is, a record of the call stack at a particular point in time) which can be printed later.

    A Throwable can also include a cause, which is a nested Throwable that represents the original problem that led to this Throwable. It is often used for wrapping various types of errors into a common Throwable without losing the detailed original error information. When printing the stack trace, the trace of the cause is included.

    See Also:
    Error, Exception, RuntimeException, Serialized Form
    • Field Detail

      • message

        public String message
        This field contains a detailed message depending on the exception actually thrown.
      • addr

        public int addr
        This field contains the machine address where the exception was thrown.
    • Constructor Detail

      • Throwable

        public Throwable()
      • Throwable

        public Throwable​(String message)
      • Throwable

        public Throwable​(Throwable cause)
      • Throwable

        public Throwable​(String message,
                         Throwable cause,
                         boolean enableSuppression,
                         boolean writableStackTrace)
    • Method Detail

      • getMessage

        public String getMessage()
      • toString

        public String toString()
        Description copied from class: Object
        Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data.
        Overrides:
        toString in class Object
        Returns:
        a printable representation of this object.
      • printStackTrace

        public void printStackTrace()
      • printStackTrace

        public void printStackTrace​(PrintStream s)
        Prints the throwable and it's stack trace to a print stream
        Parameters:
        s - PrintWriter to stream the data to.