How to print stack trace in your java code?

When debugging java code, sometimes it's important to know where you come from. So you can print current stack trace to help you.

 

1. new Exception().printStackTrace();

2. Thread.currentThread().getStackTrace(); This returns an array of StackTraceElement that represents current stack of your program.

你可能感兴趣的:(java,thread)