Getting Clojure Stacktrace

I know http://richhickey.github.com/clojure/clojure.stacktrace-api.html .

Is there a way to get the current stacktrace without throwing an exception and grabbing it?

(I am debugging a piece of code and want to grab stacks at some points so that I can analyze what is happening.)

Thanks!

+6
source share
2 answers

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) 
+7
source

This code returns an array of StackTraceElement, which is not so difficult to turn into a human-readable form :

 (.getStackTrace (Thread/currentThread)) 
+1
source

Source: https://habr.com/ru/post/915366/


All Articles