On my clojure script I have got a try/catch that should handle exception
datalayer (try (parse-dl line)
(catch Exception e []))
But when I execute my code i'have got an exception:
Caused by: com.fasterxml.jackson.core.JsonParseException: Unexpected end-of-input: was expecting closing quote for a string value
What should I do to ignore those exceptions
this is just a guess because I don't know what parse-dl does, though there is a common pattern that causes Exceptions to be thrown outside the try catch where they are expected. If you start with some lazy code in a try catch:
user> (def my-data [1 2 3])
#'user/my-data
user> (defn my-work [data]
(throw (Exception. "hi")))
#'user/my-work
user> (try
(map my-work my-data)
(catch Exception e []))
Exception hi user/my-work (form-init3735135586498578464.clj:1)
Because map returns a lazy sequence, the actual computation occurs when the REPL prints the result, so the exception is thrown after the try catch block has returned. To fix the lazy-bug, wrap the map in a call to doall
user> (try
(doall (map my-work my-data))
(catch Exception e []))
[]
Another related lazy-bug occurs when a lazy sequence is returned from a with-open expression so that by the time the computation takes place the file was already closed by the with-open macro.
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