Sets the error-handler of agent a to handler-fn. If an action
being run by the agent throws an exception or doesn't pass the
validator fn, handler-fn will be called with two arguments: the
agent and the exception.
(def bond (agent 7)) (defn err-handler-fn [ag ex] (println "evil error occured: " ex " and we still have value " @ag)) (set-error-handler! bond err-handler-fn) ;;division by zero: (send bond (fn [x] (/ x 0))) =>evil error occured: #<ArithmeticException java.lang.ArithmeticException: =>Divide by zero> and we still have value 7 (send bond inc) =>FAILURE ;;Agent is failed, needs restart, but keeps the last OK value @bond =>7 (restart-agent bond 7) ;; or replace 7 with @ag (send bond inc) =>#<Agent@88d00c6: 7> ;;because of async update @bond =>8
(defn set-error-handler!
"Sets the error-handler of agent a to handler-fn. If an action
being run by the agent throws an exception or doesn't pass the
validator fn, handler-fn will be called with two arguments: the
agent and the exception."
{:added "1.2"}
[^clojure.lang.Agent a, handler-fn]
(.setErrorHandler a handler-fn))
Comments top
No comments for set-error-handler!. Log in to add a comment.