Catch exceptions hook, line, and sinker.
fuck ai forever.
sinker is an attempt to write the smallest possible try/catch extension. it should be a seamless drop-in for existing code, and the extensions should be simple and obvious.
try+, the single public var, analyzes each form and outputs the associated code to handle them. it does its best to not waste cycles.
Catch exceptions hook, line, and sinker. fuck ai forever. sinker is an attempt to write the smallest possible `try/catch` extension. it should be a seamless drop-in for existing code, and the extensions should be simple and obvious. `try+`, the single public var, analyzes each form and outputs the associated code to handle them. it does its best to not waste cycles.
(try+ exprs* catches* finally?)it's try but nicer.
beyond normal try behavior, you can use a keyword as the catch class to catch an ex-info with :com.noahbogart.sinker/type, with the bound variable being the ex-data (can be destructured). you can also use a var (#'foo) as a catching predicate, which is called on the ex-data.
the originating exception is available in the metadata under :com.noahbogart.sinker/exception, and :default is treated as Throwable in clj and :default in cljs. (the bound variable is the whole exception in that case.)
like normal try, each catch is checked in definition order, and finally clauses gotta come last.
(require '[com.noahbogart.sinker :as sinker :refer [try+]])
(try+ (throw (ex-info "Wrong parameter" {::sinker/type :invalid-parameter
:expected :abc
:given :foobar}))
(catch :invalid-parameter {:keys [expected] :as data}
[expected (:given data)]))
;; => [:abc :foobar]
it's `try` but nicer.
beyond normal `try` behavior, you can use a keyword as the catch class to catch an `ex-info` with `:com.noahbogart.sinker/type`, with the bound variable being the ex-data (can be destructured). you can also use a var (`#'foo`) as a catching predicate, which is called on the `ex-data`.
the originating exception is available in the metadata under `:com.noahbogart.sinker/exception`, and `:default` is treated as `Throwable` in clj and `:default` in cljs. (the bound variable is the whole exception in that case.)
like normal try, each catch is checked in definition order, and finally clauses gotta come last.
```clojure
(require '[com.noahbogart.sinker :as sinker :refer [try+]])
(try+ (throw (ex-info "Wrong parameter" {::sinker/type :invalid-parameter
:expected :abc
:given :foobar}))
(catch :invalid-parameter {:keys [expected] :as data}
[expected (:given data)]))
;; => [:abc :foobar]
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |