I can see why, here's the implementation of pst:
(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)
(when-let [info (ex-data e)] (str " " (pr-str info)))))
(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))))))))))
so this works as expected:
=> *(try (throw (Exception. "a" (Exception. "cause"))) (catch Exception e
(throw e)))
(pst *e 123912031)*
Exception cause cloj2.ka/eval1430 (NO_SOURCE_FILE:1)
Exception a
cloj2.ka/eval1430 (NO_SOURCE_FILE:1)
clojure.lang.Compiler.eval (Compiler.java:6603)
clojure.lang.Compiler.eval (Compiler.java:6566)
clojure.core/eval (core.clj:2836)
clojure.main/repl/read-eval-print--6667 (main.clj:245)
clojure.main/repl/fn--6672/fn--6673 (main.clj:266)
clojure.main/repl/fn--6672 (main.clj:266)
clojure.main/repl (main.clj:264)
clojure.tools.nrepl.middleware.interruptible-eval/evaluate/fn--938
(interruptible_eval.clj:58)
clojure.core/apply (core.clj:614)
clojure.core/with-bindings* (core.clj:1785)
clojure.tools.nrepl.middleware.interruptible-eval/evaluate
(interruptible_eval.clj:43)
clojure.tools.nrepl.middleware.interruptible-eval/interruptible-eval/fn--979/fn--982
(interruptible_eval.clj:173)
clojure.core/comp/fn--4092 (core.clj:2314)
clojure.tools.nrepl.middleware.interruptible-eval/run-next/fn--972
(interruptible_eval.clj:140)
java.util.concurrent.ThreadPoolExecutor.runWorker
(ThreadPoolExecutor.java:1110)
java.util.concurrent.ThreadPoolExecutor$Worker.run
(ThreadPoolExecutor.java:603)
java.lang.Thread.run (Thread.java:722)
Caused by:
Exception cause
cloj2.ka/eval1430 (NO_SOURCE_FILE:1)
clojure.lang.Compiler.eval (Compiler.java:6603)
nil
but this doesn't:
=> *(try (throw (Exception. "a" (Exception. "cause"))) (catch Exception e
(throw e)))
(pst 123912031)*
Exception cause cloj2.ka/eval1434 (NO_SOURCE_FILE:1)
Exception cause
cloj2.ka/eval1434 (NO_SOURCE_FILE:1)
clojure.lang.Compiler.eval (Compiler.java:6603)
clojure.lang.Compiler.eval (Compiler.java:6566)
clojure.core/eval (core.clj:2836)
clojure.main/repl/read-eval-print--6667 (main.clj:245)
clojure.main/repl/fn--6672/fn--6673 (main.clj:266)
clojure.main/repl/fn--6672 (main.clj:266)
clojure.main/repl (main.clj:264)
clojure.tools.nrepl.middleware.interruptible-eval/evaluate/fn--938
(interruptible_eval.clj:58)
clojure.core/apply (core.clj:614)
clojure.core/with-bindings* (core.clj:1785)
clojure.tools.nrepl.middleware.interruptible-eval/evaluate
(interruptible_eval.clj:43)
clojure.tools.nrepl.middleware.interruptible-eval/interruptible-eval/fn--979/fn--982
(interruptible_eval.clj:173)
clojure.core/comp/fn--4092 (core.clj:2314)
clojure.tools.nrepl.middleware.interruptible-eval/run-next/fn--972
(interruptible_eval.clj:140)
java.util.concurrent.ThreadPoolExecutor.runWorker
(ThreadPoolExecutor.java:1110)
java.util.concurrent.ThreadPoolExecutor$Worker.run
(ThreadPoolExecutor.java:603)
java.lang.Thread.run (Thread.java:722)
nil
On Wed, Oct 24, 2012 at 3:27 PM, AtKaaZ <[email protected]> wrote:
> Here, (pst) doesn't see the thrown exception which is "a", it's seeing
> only it's cause:
>
> => *(try (throw (Exception. "a" (Exception. "cause"))) (catch Exception e
> (throw e)))* *(pst 123912031)*
> Exception cause datest1.core/eval3129 (NO_SOURCE_FILE:1)
> Exception cause
> datest1.core/eval3129 (NO_SOURCE_FILE:1)
> clojure.lang.Compiler.eval (Compiler.java:6603)
> clojure.lang.Compiler.eval (Compiler.java:6566)
> clojure.core/eval (core.clj:2836)
> clojure.main/repl/read-eval-print--6667 (main.clj:245)
> clojure.main/repl/fn--6672/fn--6673 (main.clj:266)
> clojure.main/repl/fn--6672 (main.clj:266)
> clojure.main/repl (main.clj:264)
> clojure.tools.nrepl.middleware.interruptible-eval/evaluate/fn--938
> (interruptible_eval.clj:58)
> clojure.core/apply (core.clj:614)
> clojure.core/with-bindings* (core.clj:1785)
> clojure.tools.nrepl.middleware.interruptible-eval/evaluate
> (interruptible_eval.clj:43)
>
> clojure.tools.nrepl.middleware.interruptible-eval/interruptible-eval/fn--979/fn--982
> (interruptible_eval.clj:173)
> clojure.core/comp/fn--4092 (core.clj:2314)
> clojure.tools.nrepl.middleware.interruptible-eval/run-next/fn--972
> (interruptible_eval.clj:140)
> java.util.concurrent.ThreadPoolExecutor.runWorker
> (ThreadPoolExecutor.java:1110)
> java.util.concurrent.ThreadPoolExecutor$Worker.run
> (ThreadPoolExecutor.java:603)
> java.lang.Thread.run (Thread.java:722)
> nil
>
> ;or, the same thing with this:
> => *(throw (Exception. "a" (Exception. "cause")))*
> Exception cause datest1.core/eval3133 (NO_SOURCE_FILE:1)
> => *(pst 21872912)*
> Exception cause
> datest1.core/eval3133 (NO_SOURCE_FILE:1)
> clojure.lang.Compiler.eval (Compiler.java:6603)
> clojure.lang.Compiler.eval (Compiler.java:6566)
> clojure.core/eval (core.clj:2836)
> clojure.main/repl/read-eval-print--6667 (main.clj:245)
> clojure.main/repl/fn--6672/fn--6673 (main.clj:266)
> clojure.main/repl/fn--6672 (main.clj:266)
> clojure.main/repl (main.clj:264)
> clojure.tools.nrepl.middleware.interruptible-eval/evaluate/fn--938
> (interruptible_eval.clj:58)
> clojure.core/apply (core.clj:614)
> clojure.core/with-bindings* (core.clj:1785)
> clojure.tools.nrepl.middleware.interruptible-eval/evaluate
> (interruptible_eval.clj:43)
>
> clojure.tools.nrepl.middleware.interruptible-eval/interruptible-eval/fn--979/fn--982
> (interruptible_eval.clj:173)
> clojure.core/comp/fn--4092 (core.clj:2314)
> clojure.tools.nrepl.middleware.interruptible-eval/run-next/fn--972
> (interruptible_eval.clj:140)
> java.util.concurrent.ThreadPoolExecutor.runWorker
> (ThreadPoolExecutor.java:1110)
> java.util.concurrent.ThreadPoolExecutor$Worker.run
> (ThreadPoolExecutor.java:603)
> java.lang.Thread.run (Thread.java:722)
> nil
>
> But here, (pst) shows the exceptions correctly (chained) shows the last
> thrown exception which is "a" and it's cause:
> => *(pst (try (throw (Exception. "a" (Exception. "cause"))) (catch
> Exception e e)))*
> Exception a
> datest1.core/eval3125/fn--3126 (NO_SOURCE_FILE:1)
> datest1.core/eval3125 (NO_SOURCE_FILE:1)
> clojure.lang.Compiler.eval (Compiler.java:6603)
> clojure.lang.Compiler.eval (Compiler.java:6566)
> clojure.core/eval (core.clj:2836)
> clojure.main/repl/read-eval-print--6667 (main.clj:245)
> clojure.main/repl/fn--6672/fn--6673 (main.clj:266)
> clojure.main/repl/fn--6672 (main.clj:266)
> clojure.main/repl (main.clj:264)
> clojure.tools.nrepl.middleware.interruptible-eval/evaluate/fn--938
> (interruptible_eval.clj:58)
> clojure.core/apply (core.clj:614)
> clojure.core/with-bindings* (core.clj:1785)
> Caused by:
> Exception cause
> datest1.core/eval3125/fn--3126 (NO_SOURCE_FILE:1)
> datest1.core/eval3125 (NO_SOURCE_FILE:1)
> nil
>
> So what is going on here? Bug ?
>
> => *clojure-version*
> {:major 1, :minor 5, :incremental 0, :qualifier "alpha6"}
>
> I also just tested with alpha7, same thing.
>
> --
> I may be wrong or incomplete.
> Please express any corrections / additions,
> they are encouraged and appreciated.
> At least one entity is bound to be transformed if you do ;)
>
>
--
I may be wrong or incomplete.
Please express any corrections / additions,
they are encouraged and appreciated.
At least one entity is bound to be transformed if you do ;)
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en