Re clj / the built-in repl:

user=> (doc pst)
-------------------------
clojure.repl/pst
([] [e-or-depth] [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.

That is, it only prints the root cause (bottom level) exception in the 
stack.

Leiningen uses its own exception printer and overrides what's in core. I'm 
not sure where exactly that's done.

Perhaps useful for debugging, you can just do *e at the repl - that will 
evaluate and print the last exception in the *e var. Exceptions have a 
built-in printer that prints the exception as data and will include the 
full stack. You can access the same functionality with the core function 
Throwable->map:

(Throwable->map *e)

Sometimes useful for investigating the truth of the matter in a consumable 
way and taking the (possibly customized) repl machinery out of the picture.






On Wednesday, October 24, 2018 at 8:52:58 PM UTC-5, Austin Haas wrote:
>
> I don't understand what is going on here. I'm trying to throw an exception 
> with a cause and sometimes the cause is included in the stacktrace and 
> sometimes it isn't.
>
> ~$ clj -Sdeps '{:deps {org.clojure/clojure {:mvn/version 
> "1.10.0-beta4"}}}'
> Clojure 1.10.0-beta4
> user=> (try (/ 1 0) (catch Exception e "caught"))
> "caught"
> user=> (try (/ 1 0) (catch Exception e (throw (Exception. "caught and 
> rethrown" e))))
> Evaluation error (ArithmeticException) at clojure.lang.Numbers.divide (
> Numbers.java:188).
> Divide by zero
> user=> (clojure.repl/pst)
> ArithmeticException Divide by zero
>  clojure.lang.Numbers.divide (Numbers.java:188)
>  clojure.lang.Numbers.divide (Numbers.java:3901)
>  user$eval3.invokeStatic (:2)
>  user$eval3.invoke (:2)
>  clojure.lang.Compiler.eval (Compiler.java:7172)
>  clojure.lang.Compiler.eval (Compiler.java:7135)
>  clojure.core/eval (core.clj:3206)
>  clojure.core/eval (core.clj:3202)
>  clojure.main/repl/read-eval-print--8898/fn--8901 (main.clj:309)
>  clojure.main/repl/read-eval-print--8898 (main.clj:307)
>  clojure.main/repl/fn--8907 (main.clj:332)
>  clojure.main/repl (main.clj:332)
> nil
>
> Same behavior with Clojure 1.8 and 1.9.
>
> If I start a REPL via lein, the cause appears:
>
> $ lein repl
> nREPL server started on port 46767 on host 127.0.0.1 - nrepl://
> 127.0.0.1:46767
> REPL-y 0.3.7, nREPL 0.2.12
> Clojure 1.8.0
> Java HotSpot(TM) 64-Bit Server VM 1.8.0_102-b14
>     Docs: (doc function-name-here)
>           (find-doc "part-of-name-here")
>   Source: (source function-name-here)
>  Javadoc: (javadoc java-object-or-class-here)
>     Exit: Control+D or (exit) or (quit)
>  Results: Stored in vars *1, *2, *3, an exception in *e
>
>
> user=> (try (/ 1 0) (catch Exception e (throw (Exception. "caught and 
> rethrown" e))))
>
>
> ArithmeticException Divide by zero  clojure.lang.Numbers.divide 
> (Numbers.java:158)
> user=> (clojure.repl/pst)
> java.lang.Exception: caught and rethrown
>                                   (Unknown Source) user/eval1736
>                                   (Unknown Source) user/eval1736
>                                 Compiler.java:6927 clojure.lang.Compiler.
> eval
>                                 Compiler.java:6890 clojure.lang.Compiler.
> eval
>                                      core.clj:3105 clojure.core/eval
>                                      core.clj:3101 clojure.core/eval
>                                       main.clj:240 clojure.main/repl[fn]
>                                       main.clj:240 clojure.main/repl[fn]
>                                       main.clj:258 clojure.main/repl[fn]
>                                       main.clj:258 clojure.main/repl
>                                       main.clj:174 clojure.main/repl
>                                   RestFn.java:1523 clojure.lang.RestFn.
> invoke
>                          interruptible_eval.clj:87 clojure.tools.nrepl.
> middleware.interruptible-eval/evaluate[fn]
>                                       AFn.java:152 clojure.lang.AFn.
> applyToHelper
>                                       AFn.java:144 clojure.lang.AFn.
> applyTo
>                                       core.clj:646 clojure.core/apply
>                                      core.clj:1881 clojure.core/with-
> bindings*
>                                      core.clj:1881 clojure.core/with-
> bindings*
>                                    RestFn.java:425 clojure.lang.RestFn.
> invoke
>                          interruptible_eval.clj:85 clojure.tools.nrepl.
> middleware.interruptible-eval/evaluate
>                          interruptible_eval.clj:55 clojure.tools.nrepl.
> middleware.interruptible-eval/evaluate
>                         interruptible_eval.clj:224 clojure.tools.nrepl.
> middleware.interruptible-eval/interruptible-eval[fn]
>                         interruptible_eval.clj:192 clojure.tools.nrepl.
> middleware.interruptible-eval/run-next[fn]
>                                        AFn.java:22 clojure.lang.AFn.run
>                       ThreadPoolExecutor.java:1142 java.util.concurrent.
> ThreadPoolExecutor.runWorker
>                        ThreadPoolExecutor.java:617 java.util.concurrent.
> ThreadPoolExecutor$Worker.run
>                                    Thread.java:745 java.lang.Thread.run
> Caused by: java.lang.ArithmeticException: Divide by zero
>                                   Numbers.java:158 clojure.lang.Numbers.
> divide
>                                  Numbers.java:3808 clojure.lang.Numbers.
> divide
> nil
>
> But if I run lein repl from inside a project directory, the cause is not 
> included:
>
> $ lein new test-project
> Generating a project called test-project based on the 'default' template.
> The default template is intended for library projects, not applications.
> To see other templates (app, plugin, etc), try `lein help new`.
> ~$ cd test-project/
> ~/test-project$ lein repl
> nREPL server started on port 36739 on host 127.0.0.1 - nrepl://127.0.0.1:
> 36739
> REPL-y 0.3.7, nREPL 0.2.12
> Clojure 1.8.0
> Java HotSpot(TM) 64-Bit Server VM 1.8.0_102-b14
>     Docs: (doc function-name-here)
>           (find-doc "part-of-name-here")
>   Source: (source function-name-here)
>  Javadoc: (javadoc java-object-or-class-here)
>     Exit: Control+D or (exit) or (quit)
>  Results: Stored in vars *1, *2, *3, an exception in *e
>
>
> user=> (try (/ 1 0) (catch Exception e (throw (Exception. "caught and 
> rethrown" e))))
> ArithmeticException Divide by zero  clojure.lang.Numbers.divide 
> (Numbers.java:158)
>
>
> user=> (clojure.repl/pst)
> ArithmeticException Divide by zero
>  clojure.lang.Numbers.divide (Numbers.java:158)
>  clojure.lang.Numbers.divide (Numbers.java:3808)
>  user/eval1244 (form-init6841584094920823421.clj:1)
>  user/eval1244 (form-init6841584094920823421.clj:1)
>  clojure.lang.Compiler.eval (Compiler.java:6927)
>  clojure.lang.Compiler.eval (Compiler.java:6890)
>  clojure.core/eval (core.clj:3105)
>  clojure.core/eval (core.clj:3101)
>  clojure.main/repl/read-eval-print--7408/fn--7411 (main.clj:240)
>  clojure.main/repl/read-eval-print--7408 (main.clj:240)
>  clojure.main/repl/fn--7417 (main.clj:258)
>  clojure.main/repl (main.clj:258)
> nil
>
> Any ideas would be appreciated.
>
> -austin
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to