I am aware of http://richhickey.github.com/clojure/clojure.stacktrace-api.html .
Is there a way to get the current stacktrace w/o throwing an exception and catching it?
(I'm debugging a piece of code, and want to capture stacktraces at certain points so I can analyze what's going on.)
Thanks!
You can obtain a stack trace from a thread – by calling the getStackTrace method on that Thread instance. This invocation returns an array of StackTraceElement, from which details about stack frames of the thread can be extracted.
The function printStackTrace() of the Exception class can take one parameter, either a PrintStream or a PrintWriter. Thus, it is possible, using a StringWriter, to print the stack trace into a String: StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw); e. printStackTrace(pw);
Therefore, you should log a stacktrace if, and only if, and always if, the exception indicates a bug in the program. However, that does not always indicate that a method you write should catch and log the exception.
A full stack trace allows you to see the chain of files from when your custom tag reached your set breakpoint. If you click on any of the pages in the caller chain then FusionDebug will show you that page and will highlight the line at which the next page in the chain was called.
use clojure.repl.pst
user=> (try (/ 1 0) (catch Exception e (pst e)))
ArithmeticException Divide by zero
clojure.lang.Numbers.divide (Numbers.java:156)
clojure.lang.Numbers.divide (Numbers.java:3691)
user/eval28 (NO_SOURCE_FILE:8)
clojure.lang.Compiler.eval (Compiler.java:6511)
clojure.lang.Compiler.eval (Compiler.java:6477)
clojure.core/eval (core.clj:2797)
clojure.main/repl/read-eval-print--6569 (main.clj:245)
clojure.main/repl/fn--6574 (main.clj:266)
clojure.main/repl (main.clj:266)
clojure.main/repl-opt (main.clj:332)
clojure.main/main (main.clj:427)
clojure.lang.Var.invoke (Var.java:423)
This code return StackTraceElement array which is not so hard to turn in readable form:
(.getStackTrace (Thread/currentThread))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With