I am thinking of creating a debug tool for my Java application.
I am wondering if it is possible to get a stack trace, just like Exception.printStackTrace()
Exception.printStackTrace()
The answer by Rob Di Marco is by far the best if you are happy to output to stderr.
stderr
If you want to capture to a String, with new lines as per a normal trace, you could do this:
String
Arrays.toString(Thread.currentThread().getStackTrace()).replace( ',', '\n' );