I understand that the "msg"
field can be accessed by
(.getMessage (ex-info "message" {:a 123}))
However, I just don't see the reason that ExceptionInfo
has a msg
field. Clojure core doesn't even provide an proper interface to access this field, e.g. (ex-msg (ex-info ...))
.
Does anyone have an example to show how to use this msg
field?
In Java, the base Throwable class from which all exceptions extend has a detailMessage field and the ExceptionInfo class inherits it. The JVM will display this message when an exception is thrown.
So, the ex-info has a message to satisfy the class hierarchy above it and to work in standard ways with Java and the JVM. The typical way to use it is to use standard Java interop call to .getMessage
like you've done in the question. You will also see it you use things like pst
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With