Throwable t = new Throwable(); StackTraceElement[] es = t.getStackTrace(); for ( int i=0; i<es.length; i++ ) { StackTraceElement e = es[i]; out.println( " in class:" + e.getClassName() + " in source file:" + e.getFileName() + " in method:" + e.getMethodName() + " at line:" + e.getLineNumber() + " " + ( e.isNativeMethod() ? "native" : "" ) ); }