Question

Trying to access the line variable of a clojure.lang.Compiler$CompilerException instance fails, yet when I inspect the code for the exception I can clearly see that the line variable exists. For example:

user=> (try
  #_=>   (load-string "(+ 2 3)\n(- 3 4)\n())")
  #_=>   (catch clojure.lang.Compiler$CompilerException er
  #_=>     (. er line)))
IllegalArgumentException No matching field found: line for class clojure.lang.Compiler$CompilerException  clojure.lang.Reflector.getInstanceField (Reflector.java:271)

When I instead expect 3 to be the result.

Not accessing the line variable, and simply returning the exception actually shows me the line!

user=> (try
  #_=>   (load-string "(+ 2 3)\n(- 3 4)\n())")
  #_=>   (catch clojure.lang.Compiler$CompilerException er
  #_=>     er))
#<CompilerException java.lang.RuntimeException: Unmatched delimiter: ), compiling:(null:3)>

What's going on?

edit: Using on clojure 1.4.0

Était-ce utile?

La solution

The line member was not added until 1.5.0 in this commit which closed CLJ-788.

You'll have to update to Clojure 1.5.0 to access this member.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top