Uncaught Exceptions in Clojure

Uncaught exceptions in Clojure sometimes disappear into the void if they happen in a background thread. Fortunately, the JVM provides a hook for adding a default handler:

  (Thread/setDefaultUncaughtExceptionHandler
   (reify Thread$UncaughtExceptionHandler
     (uncaughtException [this thread throwable]
       ;; do something with the exception here.. log it, for example.
       )))

Comments are closed.