java.lang
Class Throwable

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by java.lang.Throwable
All Implemented Interfaces:
Serializable sample code for java.io.Serializable definition code for java.io.Serializable
Direct Known Subclasses:
Error sample code for java.lang.Error definition code for java.lang.Error , Exception sample code for java.lang.Exception definition code for java.lang.Exception

public class Throwable
extends Object sample code for java.lang.Object definition code for java.lang.Object
implements Serializable sample code for java.io.Serializable definition code for java.io.Serializable

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

Instances of two subclasses, Error sample code for java.lang.Error definition code for java.lang.Error and Exception sample code for java.lang.Exception definition code for java.lang.Exception , are conventionally used to indicate that exceptional situations have occurred. Typically, these instances are freshly created in the context of the exceptional situation so as to include relevant information (such as stack trace data).

A throwable 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. Finally, it can contain a cause: another throwable that caused this throwable to get thrown. The cause facility is new in release 1.4. It is also known as the chained exception facility, as the cause can, itself, have a cause, and so on, leading to a "chain" of exceptions, each caused by another.

One reason that a throwable may have a cause is that the class that throws it is built atop a lower layered abstraction, and an operation on the upper layer fails due to a failure in the lower layer. It would be bad design to let the throwable thrown by the lower layer propagate outward, as it is generally unrelated to the abstraction provided by the upper layer. Further, doing so would tie the API of the upper layer to the details of its implementation, assuming the lower layer's exception was a checked exception. Throwing a "wrapped exception" (i.e., an exception containing a cause) allows the upper layer to communicate the details of the failure to its caller without incurring either of these shortcomings. It preserves the flexibility to change the implementation of the upper layer without changing its API (in particular, the set of exceptions thrown by its methods).

A second reason that a throwable may have a cause is that the method that throws it must conform to a general-purpose interface that does not permit the method to throw the cause directly. For example, suppose a persistent collection conforms to the Collection sample code for java.util.Collection definition code for java.util.Collection interface, and that its persistence is implemented atop java.io. Suppose the internals of the put method can throw an IOException sample code for java.io.IOException definition code for java.io.IOException . The implementation can communicate the details of the IOException to its caller while conforming to the Collection interface by wrapping the IOException in an appropriate unchecked exception. (The specification for the persistent collection should indicate that it is capable of throwing such exceptions.)

A cause can be associated with a throwable in two ways: via a constructor that takes the cause as an argument, or via the initCause(Throwable) sample code for java.lang.Throwable.initCause(java.lang.Throwable) definition code for java.lang.Throwable.initCause(java.lang.Throwable) method. New throwable classes that wish to allow causes to be associated with them should provide constructors that take a cause and delegate (perhaps indirectly) to one of the Throwable constructors that takes a cause. For example:

     try {
         lowLevelOp();
     } catch (LowLevelException le) {
         throw new HighLevelException(le);  // Chaining-aware constructor
     }
 
Because the initCause method is public, it allows a cause to be associated with any throwable, even a "legacy throwable" whose implementation predates the addition of the exception chaining mechanism to Throwable. For example:
     try {
         lowLevelOp();
     } catch (LowLevelException le) {
         throw (HighLevelException)
                 new HighLevelException().initCause(le);  // Legacy constructor
     }
 

Prior to release 1.4, there were many throwables that had their own non-standard exception chaining mechanisms ( ExceptionInInitializerError sample code for java.lang.ExceptionInInitializerError definition code for java.lang.ExceptionInInitializerError , ClassNotFoundException sample code for java.lang.ClassNotFoundException definition code for java.lang.ClassNotFoundException , UndeclaredThrowableException sample code for java.lang.reflect.UndeclaredThrowableException definition code for java.lang.reflect.UndeclaredThrowableException , InvocationTargetException sample code for java.lang.reflect.InvocationTargetException definition code for java.lang.reflect.InvocationTargetException , WriteAbortedException sample code for java.io.WriteAbortedException definition code for java.io.WriteAbortedException , PrivilegedActionException sample code for java.security.PrivilegedActionException definition code for java.security.PrivilegedActionException , PrinterIOException sample code for java.awt.print.PrinterIOException definition code for java.awt.print.PrinterIOException , RemoteException sample code for java.rmi.RemoteException definition code for java.rmi.RemoteException and NamingException sample code for javax.naming.NamingException definition code for javax.naming.NamingException ). All of these throwables have been retrofitted to use the standard exception chaining mechanism, while continuing to implement their "legacy" chaining mechanisms for compatibility.

Further, as of release 1.4, many general purpose Throwable classes (for example Exception sample code for java.lang.Exception definition code for java.lang.Exception , RuntimeException sample code for java.lang.RuntimeException definition code for java.lang.RuntimeException , Error sample code for java.lang.Error definition code for java.lang.Error ) have been retrofitted with constructors that take a cause. This was not strictly necessary, due to the existence of the initCause method, but it is more convenient and expressive to delegate to a constructor that takes a cause.

By convention, class Throwable and its subclasses have two constructors, one that takes no arguments and one that takes a String argument that can be used to produce a detail message. Further, those subclasses that might likely have a cause associated with them should have two more constructors, one that takes a Throwable (the cause), and one that takes a String (the detail message) and a Throwable (the cause).

Also introduced in release 1.4 is the getStackTrace() sample code for java.lang.Throwable.getStackTrace() definition code for java.lang.Throwable.getStackTrace() method, which allows programmatic access to the stack trace information that was previously available only in text form, via the various forms of the printStackTrace() sample code for java.lang.Throwable.printStackTrace() definition code for java.lang.Throwable.printStackTrace() method. This information has been added to the serialized representation of this class so getStackTrace and printStackTrace will operate properly on a throwable that was obtained by deserialization.

Since:
JDK1.0
See Also:
Serialized Form

Constructor Summary
Throwable sample code for java.lang.Throwable.Throwable() definition code for java.lang.Throwable.Throwable() ()
          Constructs a new throwable with null as its detail message.
Throwable sample code for java.lang.Throwable.Throwable(java.lang.String) definition code for java.lang.Throwable.Throwable(java.lang.String) (String sample code for java.lang.String definition code for java.lang.String  message)
          Constructs a new throwable with the specified detail message.
Throwable sample code for java.lang.Throwable.Throwable(java.lang.String, java.lang.Throwable) definition code for java.lang.Throwable.Throwable(java.lang.String, java.lang.Throwable) (String sample code for java.lang.String definition code for java.lang.String  message, Throwable sample code for java.lang.Throwable definition code for java.lang.Throwable  cause)
          Constructs a new throwable with the specified detail message and cause.
Throwable sample code for java.lang.Throwable.Throwable(java.lang.Throwable) definition code for java.lang.Throwable.Throwable(java.lang.Throwable) (Throwable sample code for java.lang.Throwable definition code for java.lang.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).
 
Method Summary
 Throwable sample code for java.lang.Throwable definition code for java.lang.Throwable fillInStackTrace sample code for java.lang.Throwable.fillInStackTrace() definition code for java.lang.Throwable.fillInStackTrace() ()
          Fills in the execution stack trace.
 Throwable sample code for java.lang.Throwable definition code for java.lang.Throwable getCause sample code for java.lang.Throwable.getCause() definition code for java.lang.Throwable.getCause() ()
          Returns the cause of this throwable or null if the cause is nonexistent or unknown.
 String sample code for java.lang.String definition code for java.lang.String getLocalizedMessage sample code for java.lang.Throwable.getLocalizedMessage() definition code for java.lang.Throwable.getLocalizedMessage() ()
          Creates a localized description of this throwable.
 String sample code for java.lang.String definition code for java.lang.String getMessage sample code for java.lang.Throwable.getMessage() definition code for java.lang.Throwable.getMessage() ()
          Returns the detail message string of this throwable.
 StackTraceElement sample code for java.lang.StackTraceElement definition code for java.lang.StackTraceElement [] getStackTrace sample code for java.lang.Throwable.getStackTrace() definition code for java.lang.Throwable.getStackTrace() ()
          Provides programmatic access to the stack trace information printed by printStackTrace() sample code for java.lang.Throwable.printStackTrace() definition code for java.lang.Throwable.printStackTrace() .
 Throwable sample code for java.lang.Throwable definition code for java.lang.Throwable initCause sample code for java.lang.Throwable.initCause(java.lang.Throwable) definition code for java.lang.Throwable.initCause(java.lang.Throwable) (Throwable sample code for java.lang.Throwable definition code for java.lang.Throwable  cause)
          Initializes the cause of this throwable to the specified value.
 void printStackTrace sample code for java.lang.Throwable.printStackTrace() definition code for java.lang.Throwable.printStackTrace() ()
          Prints this throwable and its backtrace to the standard error stream.
 void printStackTrace sample code for java.lang.Throwable.printStackTrace(java.io.PrintStream) definition code for java.lang.Throwable.printStackTrace(java.io.PrintStream) (PrintStream sample code for java.io.PrintStream definition code for java.io.PrintStream  s)
          Prints this throwable and its backtrace to the specified print stream.
 void printStackTrace sample code for java.lang.Throwable.printStackTrace(java.io.PrintWriter) definition code for java.lang.Throwable.printStackTrace(java.io.PrintWriter) (PrintWriter sample code for java.io.PrintWriter definition code for java.io.PrintWriter  s)
          Prints this throwable and its backtrace to the specified print writer.
 void setStackTrace sample code for java.lang.Throwable.setStackTrace(java.lang.StackTraceElement[]) definition code for java.lang.Throwable.setStackTrace(java.lang.StackTraceElement[]) (StackTraceElement sample code for java.lang.StackTraceElement definition code for java.lang.StackTraceElement [] stackTrace)
          Sets the stack trace elements that will be returned by getStackTrace() sample code for java.lang.Throwable.getStackTrace() definition code for java.lang.Throwable.getStackTrace() and printed by printStackTrace() sample code for java.lang.Throwable.printStackTrace() definition code for java.lang.Throwable.printStackTrace() and related methods.
 String sample code for java.lang.String definition code for java.lang.String toString sample code for java.lang.Throwable.toString() definition code for java.lang.Throwable.toString() ()
          Returns a short description of this throwable.
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() , equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Constructor Detail

Throwable sample code for java.lang.Throwable() definition code for java.lang.Throwable()

public Throwable()
Constructs a new throwable with null as its detail message. The cause is not initialized, and may subsequently be initialized by a call to initCause(java.lang.Throwable) sample code for java.lang.Throwable.initCause(java.lang.Throwable) definition code for java.lang.Throwable.initCause(java.lang.Throwable) .

The fillInStackTrace() sample code for java.lang.Throwable.fillInStackTrace() definition code for java.lang.Throwable.fillInStackTrace() method is called to initialize the stack trace data in the newly created throwable.


Throwable sample code for java.lang.Throwable(java.lang.String) definition code for java.lang.Throwable(java.lang.String)

public Throwable(String sample code for java.lang.String definition code for java.lang.String  message)
Constructs a new throwable with the specified detail message. The cause is not initialized, and may subsequently be initialized by a call to initCause(java.lang.Throwable) sample code for java.lang.Throwable.initCause(java.lang.Throwable) definition code for java.lang.Throwable.initCause(java.lang.Throwable) .

The fillInStackTrace() sample code for java.lang.Throwable.fillInStackTrace() definition code for java.lang.Throwable.fillInStackTrace() method is called to initialize the stack trace data in the newly created throwable.

Parameters:
message - the detail message. The detail message is saved for later retrieval by the getMessage() sample code for java.lang.Throwable.getMessage() definition code for java.lang.Throwable.getMessage() method.

Throwable sample code for java.lang.Throwable(java.lang.String, java.lang.Throwable) definition code for java.lang.Throwable(java.lang.String, java.lang.Throwable)

public Throwable(String sample code for java.lang.String definition code for java.lang.String  message,
                 Throwable sample code for java.lang.Throwable definition code for java.lang.Throwable  cause)
Constructs a new throwable with the specified detail message and cause.

Note that the detail message associated with cause is not automatically incorporated in this throwable's detail message.

The fillInStackTrace() sample code for java.lang.Throwable.fillInStackTrace() definition code for java.lang.Throwable.fillInStackTrace() method is called to initialize the stack trace data in the newly created throwable.

Parameters:
message - the detail message (which is saved for later retrieval by the getMessage() sample code for java.lang.Throwable.getMessage() definition code for java.lang.Throwable.getMessage() method).
cause - the cause (which is saved for later retrieval by the getCause() sample code for java.lang.Throwable.getCause() definition code for java.lang.Throwable.getCause() method). (A null value is permitted, and indicates that the cause is nonexistent or unknown.)
Since:
1.4

Throwable sample code for java.lang.Throwable(java.lang.Throwable) definition code for java.lang.Throwable(java.lang.Throwable)

public Throwable(Throwable sample code for java.lang.Throwable definition code for java.lang.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). This constructor is useful for throwables that are little more than wrappers for other throwables (for example, PrivilegedActionException sample code for java.security.PrivilegedActionException definition code for java.security.PrivilegedActionException ).

The fillInStackTrace() sample code for java.lang.Throwable.fillInStackTrace() definition code for java.lang.Throwable.fillInStackTrace() method is called to initialize the stack trace data in the newly created throwable.

Parameters:
cause - the cause (which is saved for later retrieval by the getCause() sample code for java.lang.Throwable.getCause() definition code for java.lang.Throwable.getCause() method). (A null value is permitted, and indicates that the cause is nonexistent or unknown.)
Since:
1.4
Method Detail

getMessage sample code for java.lang.Throwable.getMessage() definition code for java.lang.Throwable.getMessage()

public String sample code for java.lang.String definition code for java.lang.String  getMessage()
Returns the detail message string of this throwable.

Returns:
the detail message string of this Throwable instance (which may be null).

getLocalizedMessage sample code for java.lang.Throwable.getLocalizedMessage() definition code for java.lang.Throwable.getLocalizedMessage()

public String sample code for java.lang.String definition code for java.lang.String  getLocalizedMessage()
Creates a localized description of this throwable. Subclasses may override this method in order to produce a locale-specific message. For subclasses that do not override this method, the default implementation returns the same result as getMessage().

Returns:
The localized description of this throwable.
Since:
JDK1.1

getCause sample code for java.lang.Throwable.getCause() definition code for java.lang.Throwable.getCause()

public Throwable sample code for java.lang.Throwable definition code for java.lang.Throwable  getCause()
Returns the cause of this throwable or null if the cause is nonexistent or unknown. (The cause is the throwable that caused this throwable to get thrown.)

This implementation returns the cause that was supplied via one of the constructors requiring a Throwable, or that was set after creation with the initCause(Throwable) sample code for java.lang.Throwable.initCause(java.lang.Throwable) definition code for java.lang.Throwable.initCause(java.lang.Throwable) method. While it is typically unnecessary to override this method, a subclass can override it to return a cause set by some other means. This is appropriate for a "legacy chained throwable" that predates the addition of chained exceptions to Throwable. Note that it is not necessary to override any of the PrintStackTrace methods, all of which invoke the getCause method to determine the cause of a throwable.

Returns:
the cause of this throwable or null if the cause is nonexistent or unknown.
Since:
1.4

initCause sample code for java.lang.Throwable.initCause(java.lang.Throwable) definition code for java.lang.Throwable.initCause(java.lang.Throwable)

public Throwable sample code for java.lang.Throwable definition code for java.lang.Throwable  initCause(Throwable sample code for java.lang.Throwable definition code for java.lang.Throwable  cause)
Initializes the cause of this throwable to the specified value. (The cause is the throwable that caused this throwable to get thrown.)

This method can be called at most once. It is generally called from within the constructor, or immediately after creating the throwable. If this throwable was created with Throwable(Throwable) sample code for java.lang.Throwable.Throwable(java.lang.Throwable) definition code for java.lang.Throwable.Throwable(java.lang.Throwable) or Throwable(String,Throwable) sample code for java.lang.Throwable.Throwable(java.lang.String, java.lang.Throwable) definition code for java.lang.Throwable.Throwable(java.lang.String, java.lang.Throwable) , this method cannot be called even once.

Parameters:
cause - the cause (which is saved for later retrieval by the getCause() sample code for java.lang.Throwable.getCause() definition code for java.lang.Throwable.getCause() method). (A null value is permitted, and indicates that the cause is nonexistent or unknown.)
Returns:
a reference to this Throwable instance.
Throws:
IllegalArgumentException sample code for java.lang.IllegalArgumentException definition code for java.lang.IllegalArgumentException - if cause is this throwable. (A throwable cannot be its own cause.)
IllegalStateException sample code for java.lang.IllegalStateException definition code for java.lang.IllegalStateException - if this throwable was created with Throwable(Throwable) sample code for java.lang.Throwable.Throwable(java.lang.Throwable) definition code for java.lang.Throwable.Throwable(java.lang.Throwable) or Throwable(String,Throwable) sample code for java.lang.Throwable.Throwable(java.lang.String, java.lang.Throwable) definition code for java.lang.Throwable.Throwable(java.lang.String, java.lang.Throwable) , or this method has already been called on this throwable.
Since:
1.4

toString sample code for java.lang.Throwable.toString() definition code for java.lang.Throwable.toString()

public String sample code for java.lang.String definition code for java.lang.String  toString()
Returns a short description of this throwable. If this Throwable object was created with a non-null detail message string, then the result is the concatenation of three strings: If this Throwable object was created with a null detail message string, then the name of the actual class of this object is returned.

Overrides:
toString sample code for java.lang.Object.toString() definition code for java.lang.Object.toString() in class Object sample code for java.lang.Object definition code for java.lang.Object
Returns:
a string representation of this throwable.

printStackTrace sample code for java.lang.Throwable.printStackTrace() definition code for java.lang.Throwable.printStackTrace()

public void printStackTrace()
Prints this throwable and its backtrace to the standard error stream. This method prints a stack trace for this Throwable object on the error output stream that is the value of the field System.err. The first line of output contains the result of the toString() sample code for java.lang.Throwable.toString() definition code for java.lang.Throwable.toString() method for this object. Remaining lines represent data previously recorded by the method fillInStackTrace() sample code for java.lang.Throwable.fillInStackTrace() definition code for java.lang.Throwable.fillInStackTrace() . The format of this information depends on the implementation, but the following example may be regarded as typical:
 java.lang.NullPointerException
         at MyClass.mash(MyClass.java:9)
         at MyClass.crunch(MyClass.java:6)
         at MyClass.main(MyClass.java:3)
 
This example was produced by running the program:
 class MyClass {
     public static void main(String[] args) {
         crunch(null);
     }
     static void crunch(int[] a) {
         mash(a);
     }
     static void mash(int[] b) {
         System.out.println(b[0]);
     }
 }
 
The backtrace for a throwable with an initialized, non-null cause should generally include the backtrace for the cause. The format of this information depends on the implementation, but the following example may be regarded as typical:
 HighLevelException: MidLevelException: LowLevelException
         at Junk.a(Junk.java:13)
         at Junk.main(Junk.java:4)
 Caused by: MidLevelException: LowLevelException
         at Junk.c(Junk.java:23)
         at Junk.b(Junk.java:17)
         at Junk.a(Junk.java:11)
         ... 1 more
 Caused by: LowLevelException
         at Junk.e(Junk.java:30)
         at Junk.d(Junk.java:27)
         at Junk.c(Junk.java:21)
         ... 3 more
 
Note the presence of lines containing the characters "...". These lines indicate that the remainder of the stack trace for this exception matches the indicated number of frames from the bottom of the stack trace of the exception that was caused by this exception (the "enclosing" exception). This shorthand can greatly reduce the length of the output in the common case where a wrapped exception is thrown from same method as the "causative exception" is caught. The above example was produced by running the program:
 public class Junk {
     public static void main(String args[]) { 
         try {
             a();
         } catch(HighLevelException e) {
             e.printStackTrace();
         }
     }
     static void a() throws HighLevelException {
         try {
             b();
         } catch(MidLevelException e) {
             throw new HighLevelException(e);
         }
     }
     static void b() throws MidLevelException {
         c();
     }   
     static void c() throws MidLevelException {
         try {
             d();
         } catch(LowLevelException e) {
             throw new MidLevelException(e);
         }
     }
     static void d() throws LowLevelException { 
        e();
     }
     static void e() throws LowLevelException {
         throw new LowLevelException();
     }
 }

 class HighLevelException extends Exception {
     HighLevelException(Throwable cause) { super(cause); }
 }

 class MidLevelException extends Exception {
     MidLevelException(Throwable cause)  { super(cause); }
 }
 
 class LowLevelException extends Exception {
 }
 


printStackTrace sample code for java.lang.Throwable.printStackTrace(java.io.PrintStream) definition code for java.lang.Throwable.printStackTrace(java.io.PrintStream)

public void printStackTrace(PrintStream sample code for java.io.PrintStream definition code for java.io.PrintStream  s)
Prints this throwable and its backtrace to the specified print stream.

Parameters:
s - PrintStream to use for output

printStackTrace sample code for java.lang.Throwable.printStackTrace(java.io.PrintWriter) definition code for java.lang.Throwable.printStackTrace(java.io.PrintWriter)

public void printStackTrace(PrintWriter sample code for java.io.PrintWriter definition code for java.io.PrintWriter  s)
Prints this throwable and its backtrace to the specified print writer.

Parameters:
s - PrintWriter to use for output
Since:
JDK1.1

fillInStackTrace sample code for java.lang.Throwable.fillInStackTrace() definition code for java.lang.Throwable.fillInStackTrace()

public Throwable sample code for java.lang.Throwable definition code for java.lang.Throwable  fillInStackTrace()
Fills in the execution stack trace. This method records within this Throwable object information about the current state of the stack frames for the current thread.

Returns:
a reference to this Throwable instance.
See Also:
printStackTrace() sample code for java.lang.Throwable.printStackTrace() definition code for java.lang.Throwable.printStackTrace()

getStackTrace sample code for java.lang.Throwable.getStackTrace() definition code for java.lang.Throwable.getStackTrace()

public StackTraceElement sample code for java.lang.StackTraceElement definition code for java.lang.StackTraceElement [] getStackTrace()
Provides programmatic access to the stack trace information printed by printStackTrace() sample code for java.lang.Throwable.printStackTrace() definition code for java.lang.Throwable.printStackTrace() . Returns an array of stack trace elements, each representing one stack frame. The zeroth element of the array (assuming the array's length is non-zero) represents the top of the stack, which is the last method invocation in the sequence. Typically, this is the point at which this throwable was created and thrown. The last element of the array (assuming the array's length is non-zero) represents the bottom of the stack, which is the first method invocation in the sequence.

Some virtual machines may, under some circumstances, omit one or more stack frames from the stack trace. In the extreme case, a virtual machine that has no stack trace information concerning this throwable is permitted to return a zero-length array from this method. Generally speaking, the array returned by this method will contain one element for every frame that would be printed by printStackTrace.

Returns:
an array of stack trace elements representing the stack trace pertaining to this throwable.
Since:
1.4

setStackTrace sample code for java.lang.Throwable.setStackTrace(java.lang.StackTraceElement[]) definition code for java.lang.Throwable.setStackTrace(java.lang.StackTraceElement[])

public void setStackTrace(StackTraceElement sample code for java.lang.StackTraceElement definition code for java.lang.StackTraceElement [] stackTrace)
Sets the stack trace elements that will be returned by getStackTrace() sample code for java.lang.Throwable.getStackTrace() definition code for java.lang.Throwable.getStackTrace() and printed by printStackTrace() sample code for java.lang.Throwable.printStackTrace() definition code for java.lang.Throwable.printStackTrace() and related methods. This method, which is designed for use by RPC frameworks and other advanced systems, allows the client to override the default stack trace that is either generated by fillInStackTrace() sample code for java.lang.Throwable.fillInStackTrace() definition code for java.lang.Throwable.fillInStackTrace() when a throwable is constructed or deserialized when a throwable is read from a serialization stream.

Parameters:
stackTrace - the stack trace elements to be associated with this Throwable. The specified array is copied by this call; changes in the specified array after the method invocation returns will have no affect on this Throwable's stack trace.
Throws:
NullPointerException sample code for java.lang.NullPointerException definition code for java.lang.NullPointerException - if stackTrace is null, or if any of the elements of stackTrace are null
Since:
1.4