@ SuppressWarnings ( { "ThrowCaughtLocally" } ) public static StackTraceElement [ ] getCurrentStackTrace ( ) { StackTraceElement [ ] ste = new Exception ( ) . getStackTrace ( ) ; if ( ste . length > 1 ) { StackTraceElement [ ] result = new StackTraceElement [ ste . length - 1 ] ; System . arraycopy ( ste , 1 , result , 0 , ste . length - 1 ) ; return result ; } else { return ste ; } }
Returns current stack trace in form of array of stack trace elements . First stack trace element is removed . Since an exception is thrown internally this method is slow .