You can use [Thread.currentThread().getStackTrace()](https://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html#getStackTrace\(\)).

That returns an array of StackTraceElements that represent the current stack trace of a program.