How do I print the stack trace of an exception to a stream other than stderr? One way I found is to use getStackTrace() and print the entire list to the stream.
Throwable.printStackTrace(..) can take a PrintWriter or PrintStream argument:
Throwable.printStackTrace(..)
PrintWriter
PrintStream
} catch (Exception ex) { ex.printStackTrace(new java.io.PrintStream(yourOutputStream)); }
That said, consider using a logger interface like SLF4J with an logging implementation like LOGBack or log4j.