Skip to content

Instantly share code, notes, and snippets.

@ifesdjeen
Created June 26, 2012 14:47
Show Gist options
  • Save ifesdjeen/2996213 to your computer and use it in GitHub Desktop.
Save ifesdjeen/2996213 to your computer and use it in GitHub Desktop.
Global Exception catching
;; That will actually catch exception within inner thread, too. And within inner thread of inner thread. Etc.
(Thread/setDefaultUncaughtExceptionHandler (proxy [Thread$UncaughtExceptionHandler] []
(uncaughtException [t e]
;;
;; Your fancy Exception logging here
;;
(println "Throwable: " + (.getMessage e))
(println (.toString t)))))
(.start (Thread. (cast Runnable
(fn []
(throw (Exception. "INNER THREAD EXCEPTION!!"))))))
;;Throwable: #<core$_PLUS_ clojure.core$_PLUS_@292ade54> INNER THREAD EXCEPTION!!
;;Thread[Thread-1,5,main]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment