Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of "msg" parameter of "ex-info"?

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?

like image 719
Ming Avatar asked Jan 06 '17 05:01

Ming


1 Answers

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.

like image 125
Alex Miller Avatar answered Sep 23 '22 15:09

Alex Miller