Is there a way to dump a stack trace without throwing an exception in java?

corgrath picture corgrath · Jun 3, 2009 · Viewed 73.7k times · Source

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() but without actually throwing an exception?

My goal is to, in any given method, dump a stack to see who the method caller is.

Answer

Rob Di Marco picture Rob Di Marco · Jun 3, 2009

Yes, simply use

Thread.dumpStack()