mirror of
https://github.com/taoensso/telemere.git
synced 2025-12-24 04:18:26 +00:00
`catch->error!` with default opts is quite handy for use with `trace!`/`spy!`. But there's a lot that users might want to customize, including: - Exactly what error type to catch. - Whether or not to rethrow on catch. - Error binding sym to enable use within signal message, data, etc. We could support all of this via `catch->error!` opts but there's not much point. If anyway customizing such behaviour, it'd be better for the user to just use an appropriate `try/catch`. So I've now documented this recommendation, and removed all but the most basic (:catch-val) options. This is a BREAKING change for anyone that was previously using any of the following options: :rethrow? :catch-sym Note that `:rethrow?` was never particularly helpful (independently of `:catch-val` anyway), and the removal of `:catch-sym` will throw a compile-time error for any existing users.
39 lines
1.5 KiB
Text
39 lines
1.5 KiB
Text
ALWAYS (unconditionally) executes given `run` form and:
|
|
If `run` form succeeds: returns the form's result.
|
|
If `run` form throws ANYTHING:
|
|
Calls `error!` with the thrown error and given signal options [2], then
|
|
either returns given (:catch-val opts), or rethrows.
|
|
|
|
Default kind: `:error`
|
|
Default level: `:error`
|
|
|
|
Just a convenience util. For more flexibility use your own `try/catch`.
|
|
See `taoensso.encore/try*` for easily catching cross-platform errors.
|
|
|
|
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]
|
|
:catch-val "Return value iff form throws"}
|
|
|
|
(/ 1 0)) ; %> {... :data {x "x"}, :msg_ "My msg: x" ...}
|
|
|
|
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.)
|