I am trying to understand what is happening with a program where I have exceptions that "disappear" without any notice (and the thread stops working).
The simplest case that I could reproduce is this:
(defn -main []
(let [a (future (do (println "Ouch... ")
(/ 0 0)
(println "We never arrive here")))]
(Thread/sleep 1000)
(println "Hmmmm" @a)))
Of course, when running in repl (or using lein), I get an exception:
so.core> (-main)
Ouch...
ArithmeticException Divide by zero clojure.lang.Numbers.divide (Numbers.java:156)
What kind of behavior I expected.
However, now if I remove the dereferencing of the future:
(defn -main []
(let [a (future (do (println "Ouch... ")
(/ 0 0)
(println "We never arrive here")))]
(Thread/sleep 1000)
(println "Hmmmm")))
Here's the conclusion:
so.core> (-main)
Ouch...
Hmmmm
nil
so.core>
So, the future is fulfilled (otherwise “Ouch ...” will not be printed), and, obviously, the exception is then thrown (otherwise “We will never come here” will print) ... But this exception should not be anywhere and the program continues, as if everything is in order.
-, , , , ( stdout), .
?
() Emacs/?
(, ) "" , - ?
try/catch?
?
" ", ?
Java/ Clojure , , , .