I've had the case several times where exception in futures would prove hard to track down (and already asked a question here about why some exception seemed never to happen and this question is not a dupe of my older question) and decided to try to set a "default uncaught exception handler".
However I can't make it work. I tried using reify and I tried using a proxy. It's as if nothing was happening.
Here's a minimal case reproducing the issue:
REPL> (Thread/setDefaultUncaughtExceptionHandler
(proxy [Thread$UncaughtExceptionHandler] []
(uncaughtException [thread throwable]
(do (println (-> throwable .getCause .getMessage))
; (error "whatever...") ; some 'timbre' logging if you have timbre
))))
nil
REPL> (future (do (Thread/sleep 100) (/ 0 0)))
#<core$future_call$reify__6267@c2909a1: :pending>
REPL>
I tried println, I tried logging to a file using timbre, I tried to spit to a temp file, I tried to force the future to be run by deref'ing... Apparently the default uncaught exception handler is never called.
Could anyone show me an interactive / REPL example of a working default uncaught exception handler actually catching an exception?
As a bonus question: once a default uncaught exception handler is set, is there an easy way to "see" that it is set? And what happens in the REPL when you are testing that feature and call setDefaultUncaughtExceptionHandler several time? Is only the last handler taken into account?