You're viewing version 1.2.0 of print-stack-trace. The latest stable version of Clojure Core is 1.3.0.
1.2.0 Arrow_down_16x16

print-stack-trace

clojure.stacktrace

  • (print-stack-trace tr)
  • (print-stack-trace tr n)
Prints a Clojure-oriented stack trace of tr, a Throwable.
Prints a maximum of n stack frames (default: unlimited).
Does not print chained exceptions (causes).

1 Example top

  • user=> (clojure.stacktrace/print-stack-trace (Exception. "foo"))
    java.lang.Exception: foo
     at user$eval112.invoke (NO_SOURCE_FILE:1)
        clojure.lang.Compiler.eval (Compiler.java:6619)
        clojure.lang.Compiler.eval (Compiler.java:6582)
        clojure.core$eval.invoke (core.clj:2852)
        clojure.main$repl$read_eval_print__6588$fn__6591.invoke (main.clj:259)
        clojure.main$repl$read_eval_print__6588.invoke (main.clj:259)
        clojure.main$repl$fn__6597.invoke (main.clj:277)
        clojure.main$repl.doInvoke (main.clj:277)
        clojure.lang.RestFn.invoke (RestFn.java:1096)
        clojure.tools.nrepl.middleware.interruptible_eval$evaluate$fn__3615.invoke (interruptible_eval.clj:56)
        clojure.lang.AFn.applyToHelper (AFn.java:159)
        clojure.lang.AFn.applyTo (AFn.java:151)
        clojure.core$apply.invoke (core.clj:617)
        clojure.core$with_bindings_STAR_.doInvoke (core.clj:1788)
        clojure.lang.RestFn.invoke (RestFn.java:425)
        clojure.tools.nrepl.middleware.interruptible_eval$evaluate.invoke (interruptible_eval.clj:41)
        clojure.tools.nrepl.middleware.interruptible_eval$interruptible_eval$fn__3656$fn__3659.invoke (interruptible_eval.clj:171)
        clojure.core$comp$fn__4154.invoke (core.clj:2330)
        clojure.tools.nrepl.middleware.interruptible_eval$run_next$fn__3649.invoke (interruptible_eval.clj:138)
        clojure.lang.AFn.run (AFn.java:24)
        java.util.concurrent.ThreadPoolExecutor.runWorker (:-1)
        java.util.concurrent.ThreadPoolExecutor$Worker.run (:-1)
        java.lang.Thread.run (:-1)
    nil
    
    user=> (clojure.stacktrace/print-stack-trace (Exception. "foo") 4)
    java.lang.Exception: foo
     at user$eval124.invoke (NO_SOURCE_FILE:1)
        clojure.lang.Compiler.eval (Compiler.java:6619)
        clojure.lang.Compiler.eval (Compiler.java:6582)
        clojure.core$eval.invoke (core.clj:2852)
    nil
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source clojure/stacktrace.clj:44 top

(defn print-stack-trace
  "Prints a Clojure-oriented stack trace of tr, a Throwable.
  Prints a maximum of n stack frames (default: unlimited).
  Does not print chained exceptions (causes)."
  {:added "1.1"}
  ([tr] (print-stack-trace tr nil))
  ([tr n]
     (let [st (.getStackTrace tr)]
       (print-throwable tr)
       (newline)
       (print " at ") 
       (print-trace-element (first st))
       (newline)
       (doseq [e (if (nil? n)
		   (rest st)
		   (take (dec n) (rest st)))]
	 (print "    ")
	 (print-trace-element e)
	 (newline)))))
Vars in clojure.stacktrace/print-stack-trace: defn doseq first let newline print
Used in 0 other vars

Comments top

No comments for print-stack-trace. Log in to add a comment.