Over a million developers have joined DZone.

How Did I Get Here, Java?

·
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 );
   }
}
Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}