Dave's Brain

Browse - Programming Tips - How can I programatically make a stack trace?

Date: 2014oct9
Language: Java

Q.  How can I programatically make a stack trace?


A.  Add this function to your code and call it when you want:

public static void stacktrace() { for (final StackTraceElement ste : Thread.currentThread().getStackTrace()) { System.out.println(ste.toString()); } }
Example use:
if (somethingIsWrong()) { stacktrace(); }

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.