mirror of
https://github.com/taoensso/telemere.git
synced 2025-12-27 13:48:25 +00:00
Objectives:
- Support single map opts arg in all cases.
- Make it easier for folks to inspect the source to understand how
the common creators use/wrap underlying `signal!`.
Also updated relevant docstrings, etc.
38 lines
1.4 KiB
Text
38 lines
1.4 KiB
Text
ALWAYS (unconditionally) executes given `run` form and:
|
|
If `run` form succeeds: return the form's result.
|
|
If `run` form throws:
|
|
Call `error!` with the thrown error and the given signal options [2],
|
|
then return (:catch-val opts) if it exists, or rethrow the error.
|
|
|
|
Default kind: `:error`
|
|
Default level: `:error`
|
|
|
|
Examples:
|
|
|
|
(catch->error! (/ 1 0)) ; %> {:kind :error, :level :error, :error <caught> ...}
|
|
(catch->error! ::my-id (/ 1 0)) ; %> {... :id ::my-id ...}
|
|
(catch->error!
|
|
{:let [x "x"] ; Available to `:data` and `:msg`
|
|
:data {:x x}
|
|
:msg ["My msg:" x my-error]
|
|
:catch-val "Return value when form throws"
|
|
:catch-sym my-error ; Sym of caught error, available to `:data` and `:msg`
|
|
}
|
|
|
|
(/ 1 0)) ; %> {... :data {x "x"}, :msg_ "My msg: x <caught>" ...}
|
|
|
|
Tips:
|
|
|
|
- Test using `with-signal`: (with-signal (catch->error! ...)).
|
|
- Supports the same options [2] as other signals [1].
|
|
|
|
- Useful for preventing errors from going unnoticed in futures, callbacks,
|
|
agent actions, etc.!: (future (catch->error ::my-future (do-something)))
|
|
|
|
See also `error!`.
|
|
|
|
----------------------------------------------------------------------
|
|
[1] See `help:signal-creators` - (`signal!`, `log!`, `event!`, ...)
|
|
[2] See `help:signal-options` - {:keys [kind level id data ...]}
|
|
[3] See `help:signal-content` - {:keys [kind level id data ...]}
|
|
[4] See `help:signal-filters` - (by ns/kind/id/level, sampling, etc.)
|