clojure.java-time icon indicating copy to clipboard operation
clojure.java-time copied to clipboard

Catchable exceptions

Open devurandom opened this issue 1 year ago • 2 comments

When conversion fails, java-time.api wraps the java.time.format.DateTimeParseException in clojure.lang.ExceptionInfo, which I cannot distinguish from any other exception when trying to catch:

(import '(java.time.format DateTimeParseException))

(try
  (t/zoned-date-time "2024-04-08T00:00:00")
  (catch DateTimeParseException _
    (println "CAUGHT")))

java.time.format.DateTimeParseException: Text '2024-04-08T00:00:00' could not be parsed at index 19
             clojure.lang.ExceptionInfo: Conversion failed

It would be convenient if java-time.api would throw with some form of :type key in the map that I could catch with e.g. https://github.com/gfredericks/catch-data, or if it would pass through the original Java exceptions.

devurandom avatar Apr 08 '24 15:04 devurandom

I wasn't aware of this, where does this rethrowing happen?

frenchy64 avatar Nov 16 '24 01:11 frenchy64

I am currently not at my computer to be able to look at the stack trace, but I found this by searching for catch in the code: https://github.com/dm3/clojure.java-time/blob/ee7620f141f45a3d9ebec26004a4f4ee10a7ecb0/src/java_time/defconversion.clj#L60-L65

devurandom avatar Nov 16 '24 08:11 devurandom