DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

How Did I Get Here, Java?

04.30.2010
| 1501 views |
  • submit to reddit
        Generate and print a stacktrace to show how execution landed in a spot in code. 
Old school debugging.

try {
   throw new RuntimeException();
} catch( Exception e ) {
   for ( StackTraceElement l : e.getStackTrace() ) {
      System.out.println( ":" + l );
   }
}