Intel

Developer Zone

Throwable

java.lang

Class Throwable

  • Direct Known Subclasses:
    Error, Exception


    public class Throwable
    extends Object
    The superclass of all classes which can be thrown by the virtual machine. 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
    • Constructor Summary

      Constructors
      Constructor and Description
      Throwable()
      Constructs a new Throwable that includes the current stack trace.
      Throwable(String detailMessage)
      Constructs a new Throwable with the current stack trace and the specified detail message.
    • Method Summary

      Methods
      Modifier and Type Method and Description
      Throwable fillInStackTrace()
      Records the stack trace from the point where this method has been called to this Throwable.
      String getMessage()
      Returns the extra information message which was provided when this Throwable was created.
      StackTraceElement[] getStackTrace()
      Returns the array of stack trace elements of this Throwable.
      void printStackTrace()
      Writes a printable representation of this Throwable's stack trace to the System.err stream.
      void printStackTrace(PrintStream err)
      Writes a printable representation of this Throwable's stack trace to the specified print stream.
      String toString()
      Returns the current String representation of this throwable object.
    • Constructor Detail

      • Throwable

        public Throwable()
        Constructs a new Throwable that includes the current stack trace.
      • Throwable

        public Throwable(String detailMessage)
        Constructs a new Throwable with the current stack trace and the specified detail message.
        Parameters:
        detailMessage - the detail message for this Throwable.
    • Method Detail

      • fillInStackTrace

        public Throwable fillInStackTrace()
        Records the stack trace from the point where this method has been called to this Throwable. The method is public so that code which catches a Throwable and then re-throws it can adjust the stack trace to represent the location where the exception was re-thrown.
        Returns:
        this Throwable instance.
      • getMessage

        public String getMessage()
        Returns the extra information message which was provided when this Throwable was created. Returns null if no message was provided at creation time.
        Returns:
        this Throwable's detail message.
      • getStackTrace

        public StackTraceElement[] getStackTrace()
        Returns the array of stack trace elements of this Throwable. Each StackTraceElement represents an entry in the call stack. The element at position 0 is the top of the stack, that is, the stack frame where this Throwable is thrown.
        Returns:
        a copy of the array of StackTraceElements representing the call stack. Changes in the array obtained from this call will not change the call stack stored in this Throwable.
        See Also:
        printStackTrace()
      • printStackTrace

        public void printStackTrace()
        Writes a printable representation of this Throwable's stack trace to the System.err stream.
      • printStackTrace

        public void printStackTrace(PrintStream err)
        Writes a printable representation of this Throwable's stack trace to the specified print stream. If the Throwable contains a cause, the method will be invoked recursively for the nested Throwable.
        Parameters:
        err - the stream to write the stack trace on.
      • toString

        public String toString()
        Returns the current String representation of this throwable object.
        Overrides:
        toString in class Object
        Returns:
        a String containing current String representation of this throwable object.