Airat
Airat

Reputation: 73

How can I retrieve full, multi-line Clojure exception content as a string?

(try
  (/ 1 0)
  (catch Exception e
    (prn e)))

prints in REPL as

#error {
 :cause Divide by zero
 :via
 [{:type java.lang.ArithmeticException
   :message Divide by zero
   :at [clojure.lang.Numbers divide Numbers.java 158]}]
 :trace
 [[clojure.lang.Numbers divide Numbers.java 158]
  ......................
  [java.lang.Thread run Thread.java 745]]}

How to get this complete and comprehensible message with str?

(try
  (/ 1 0)
  (catch Exception e
    (str e)))

return only

=> "java.lang.ArithmeticException: Divide by zero"

Upvotes: 3

Views: 153

Answers (1)

Airat
Airat

Reputation: 73

Solution is very simple

(pr-str e)

Upvotes: 3

Related Questions