1.3.0 permalink Arrow_down_16x16
  • (pst)
  • (pst e-or-depth)
  • (pst e depth)
Prints a stack trace of the exception, to the depth requested. If none supplied, uses the root cause of the
most recent repl exception (*e), and a depth of 12.

1 Example top

  • user=> (pst)
    nil
    
    user=> (/ 1 0)
    ArithmeticException Divide by zero  clojure.lang.Numbers.divide (Numbers.java:156)
    
    user=> (pst)
    ArithmeticException Divide by zero
    	clojure.lang.Numbers.divide (Numbers.java:156)
    	clojure.lang.Numbers.divide (Numbers.java:3691)
    	user/eval13 (NO_SOURCE_FILE:7)
    	clojure.lang.Compiler.eval (Compiler.java:6619)
    	clojure.lang.Compiler.eval (Compiler.java:6582)
    	clojure.core/eval (core.clj:2852)
    	clojure.main/repl/read-eval-print--6588/fn--6591 (main.clj:259)
    	clojure.main/repl/read-eval-print--6588 (main.clj:259)
    	clojure.main/repl/fn--6597 (main.clj:277)
    	clojure.main/repl (main.clj:277)
    	clojure.main/repl-opt (main.clj:343)
    	clojure.main/main (main.clj:441)
    nil
    
Log in to add / edit an example.

See Also top

  • 0
    clojure.core/*e

    bound in a repl thread to the most recent exception caught by the rep

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/repl.clj:242 top

(defn pst
  "Prints a stack trace of the exception, to the depth requested. If none supplied, uses the root cause of the
  most recent repl exception (*e), and a depth of 12."
  {:added "1.3"}
  ([] (pst 12))
  ([e-or-depth]
     (if (instance? Throwable e-or-depth)
       (pst e-or-depth 12)
       (when-let [e *e]
         (pst (root-cause e) e-or-depth))))
  ([^Throwable e depth]
     (binding [*out* *err*]
       (println (str (-> e class .getSimpleName) " " (.getMessage e)))
       (let [st (.getStackTrace e)
             cause (.getCause e)]
         (doseq [el (take depth
                          (remove #(#{"clojure.lang.RestFn" "clojure.lang.AFn"} (.getClassName %))
                                  st))]
           (println (str \tab (stack-element-str el))))
         (when cause
           (println "Caused by:")
           (pst cause (min depth
                           (+ 2 (- (count (.getStackTrace cause))
                                   (count st))))))))))
Vars in clojure.repl/pst:
Used in 0 other vars

Comments top

No comments for pst. Log in to add a comment.