Search code examples
clojure

How can I get the call stack in Clojure?


I have a point in my clojure code where I want to know what the call stack was (ie: list of clojure functions used to get there). How can I do this?


Solution

  • This isn't the nicest solution, but it's simple and it should work in core clojure:

    (try (throw (Exception. "")) (catch Exception e (.printStackTrace e *out*)))
    

    You can inspect e in code if you want something other than a printed version. See also clojure.stacktrace in the current master branch or clj-stacktrace for clojure 1.2.