mirror of
https://github.com/status-im/timbre.git
synced 2025-02-16 21:56:21 +00:00
Add handle-uncaught-jvm-exceptions!
util
This commit is contained in:
parent
621ffe83d1
commit
379bf9d876
@ -460,10 +460,25 @@
|
|||||||
|
|
||||||
(defmacro logged-future [& body] `(future (log-errors ~@body)))
|
(defmacro logged-future [& body] `(future (log-errors ~@body)))
|
||||||
|
|
||||||
|
#+clj
|
||||||
|
(defn handle-uncaught-jvm-exceptions!
|
||||||
|
"Sets JVM-global DefaultUncaughtExceptionHandler."
|
||||||
|
[& [handler]]
|
||||||
|
(let [handler
|
||||||
|
(or handler
|
||||||
|
(fn [throwable ^Thread thread]
|
||||||
|
(errorf throwable "Uncaught exception on thread: %s"
|
||||||
|
(.getName thread))))]
|
||||||
|
|
||||||
|
(Thread/setDefaultUncaughtExceptionHandler
|
||||||
|
(reify Thread$UncaughtExceptionHandler
|
||||||
|
(uncaughtException [this thread throwable] (handler throwable thread))))))
|
||||||
|
|
||||||
(comment
|
(comment
|
||||||
(log-errors (/ 0))
|
(log-errors (/ 0))
|
||||||
(log-and-rethrow-errors (/ 0))
|
(log-and-rethrow-errors (/ 0))
|
||||||
(logged-future (/ 0)))
|
(logged-future (/ 0))
|
||||||
|
(handle-uncaught-jvm-exceptions!))
|
||||||
|
|
||||||
(defmacro spy
|
(defmacro spy
|
||||||
"Evaluates named expression and logs its result. Always returns the result.
|
"Evaluates named expression and logs its result. Always returns the result.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user