Java Data Type Tutorial - Java Throwable .setStackTrace (StackTraceElement [] stackTrace)








Syntax

Throwable.setStackTrace(StackTraceElement [] stackTrace) has the following syntax.

public void setStackTrace(StackTraceElement [] stackTrace)

Example

In the following code shows how to use Throwable.setStackTrace(StackTraceElement [] stackTrace) method.

import java.io.FileNotFoundException;
import java.io.PrintWriter;
// ww w .  j av a  2  s.c o m

public class Main {
  public static void main(String[] argv) throws FileNotFoundException {
    Throwable t = new Exception("from java2s.com");
    
    t.setStackTrace(new Exception("java2s.com").getStackTrace());


  }

}