user1383359
user1383359

Reputation: 2753

Getting Clojure Stacktrace

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!

Upvotes: 6

Views: 1959

Answers (2)

om-nom-nom
om-nom-nom

Reputation: 62835

This code return StackTraceElement array which is not so hard to turn in readable form:

(.getStackTrace (Thread/currentThread))

Upvotes: 1

number23_cn
number23_cn

Reputation: 4619

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)

Upvotes: 8

Related Questions