I'm just starting to learn Clojure and struggling to extract Exception metadata. When I run this:
(try
(/ 1 0)
(catch Exception error (println error)))
I get an ArithmeticException, as expected. The stacktrace printed looks like this:
#error {
:cause Divide by zero
:via
[{:type java.lang.ArithmeticException
:message Divide by zero
:at [clojure.lang.Numbers divide Numbers.java 188]}]
:trace
[[clojure.lang.Numbers divide Numbers.java 188]
[clojure.lang.Numbers divide Numbers.java 3901]
...
]}
It looks like a map to me, so I tried to extract the value from :cause with (:cause error), but it evaluates to nil.
How can I do that?
UPDATE:
After digging a bit, I found that #error {...} is a java.lang.Throwable class, is that correct?
I tried using Java interop (.getCause error), but also returns nil. Turns out (.getMessage) error) does return "Divide by zero".
Are there other ways to get specific attributes from that class, other than .getMessage()?