Java tutorial
import java.io.FileNotFoundException; import java.io.PrintWriter; public class Main { public static void main(String[] argv) throws FileNotFoundException { Throwable t = new Exception("from java2s.com"); t.printStackTrace(new PrintWriter("file.name")); } }