clojure中的错误/异常的完整堆栈跟踪

时间:2018-03-28 07:52:11

标签: exception clojure jvm leiningen

我正在使用lein的clojure。从repl执行函数会出现以下错误消息:

ClassCastException java.lang.Long cannot be cast to clojure.lang.IFn  user/eval3873/fn--3874 (form-init6374407951848346782.clj:1)

因此,在代码中的某个位置放置了一个长的位置,它应该是一个函数。但我无法弄清错误in my code的位置。有没有办法让repl打印异常的完整堆栈跟踪?

1 个答案:

答案 0 :(得分:5)

只需检查特殊变量*e,这也在REPL介绍横幅中有所描述。

例如:

Clojure 1.8.0
Java HotSpot(TM) 64-Bit Server VM 1.8.0_161-b12
    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=> (+ 1 "r")

ClassCastException java.lang.String cannot be cast to java.lang.Number  clojure.lang.Numbers.add (Numbers.java:128)
user=> *e
#error {
 :cause "java.lang.String cannot be cast to java.lang.Number"
 :via
 [{:type java.lang.ClassCastException
   :message "java.lang.String cannot be cast to java.lang.Number"
   :at [clojure.lang.Numbers add "Numbers.java" 128]}]
 :trace
 [[clojure.lang.Numbers add "Numbers.java" 128]
  [clojure.lang.Numbers add "Numbers.java" 3640]
  [user$eval1244 invokeStatic "form-init8915652650489400713.clj" 1]
  [user$eval1244 invoke "form-init8915652650489400713.clj" 1]
  [clojure.lang.Compiler eval "Compiler.java" 6927]
  [clojure.lang.Compiler eval "Compiler.java" 6890]
  [clojure.core$eval invokeStatic "core.clj" 3105]
  [clojure.core$eval invoke "core.clj" 3101]
  [clojure.main$repl$read_eval_print__7408$fn__7411 invoke "main.clj" 240]
  [clojure.main$repl$read_eval_print__7408 invoke "main.clj" 240]
  [clojure.main$repl$fn__7417 invoke "main.clj" 258]
  [clojure.main$repl invokeStatic "main.clj" 258]
  [clojure.main$repl doInvoke "main.clj" 174]
  [clojure.lang.RestFn invoke "RestFn.java" 1523]
  [clojure.tools.nrepl.middleware.interruptible_eval$evaluate$fn__648 invoke "interruptible_eval.clj" 87]
  [clojure.lang.AFn applyToHelper "AFn.java" 152]
  [clojure.lang.AFn applyTo "AFn.java" 144]
  [clojure.core$apply invokeStatic "core.clj" 646]
  [clojure.core$with_bindings_STAR_ invokeStatic "core.clj" 1881]
  [clojure.core$with_bindings_STAR_ doInvoke "core.clj" 1881]
  [clojure.lang.RestFn invoke "RestFn.java" 425]
  [clojure.tools.nrepl.middleware.interruptible_eval$evaluate invokeStatic "interruptible_eval.clj" 85]
  [clojure.tools.nrepl.middleware.interruptible_eval$evaluate invoke "interruptible_eval.clj" 55]
  [clojure.tools.nrepl.middleware.interruptible_eval$interruptible_eval$fn__693$fn__696 invoke "interruptible_eval.clj" 222]
  [clojure.tools.nrepl.middleware.interruptible_eval$run_next$fn__688 invoke "interruptible_eval.clj" 190]
  [clojure.lang.AFn run "AFn.java" 22]
  [java.util.concurrent.ThreadPoolExecutor runWorker "ThreadPoolExecutor.java" 1149]
  [java.util.concurrent.ThreadPoolExecutor$Worker run "ThreadPoolExecutor.java" 624]
  [java.lang.Thread run "Thread.java" 748]]}
user=>