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 merges similar/overlapping catch clauses, uses cond or case where appropriate, and 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 merges similar/overlapping `catch` clauses, uses `cond` or `case` where appropriate, and does its best to not waste cycles.
(emit-catches t ex-info? data catch-clauses)for each catch type, emit the cond+ branches that match the exception and then execute the catch body.
for a keyword or fn match, attach the exception as ::exception metadata
for each catch type, emit the cond+ branches that match the exception and then execute the catch body. for a keyword or fn match, attach the exception as ::exception metadata
(emit-exprs exprs)Instead of emitting the body directly, wrap expr in a let and do to prevent unwanted recur targets or any catch or finally clauses that we didn't catch otherwise
Instead of emitting the body directly, wrap `expr` in a `let` and `do` to prevent unwanted recur targets or any `catch` or `finally` clauses that we didn't catch otherwise
(emit-finallys finally-clauses)don't do anything for finallys, they're perfect just the way they are
don't do anything for finallys, they're perfect just the way they are
(index-of coll pred)returns idx or nil if pred doesn't match
returns idx or nil if pred doesn't match
(parse-catch-clause clause)Given a (catch ...) clause, what kind of catch should we generate?
:keyword => dispatch on type'symbol => dispatch on class (using instance?)#'var => dispatch as a predicatereturn a map of {:pred :id :body :type} where :type is one of :catch/default, :catch/type, :catch/raw, :catch/class, :catch/fn
Given a `(catch ...)` clause, what kind of catch should we generate?
* `:keyword` => dispatch on type
* `'symbol` => dispatch on class (using `instance?`)
* `#'var` => dispatch as a predicate
* otherwise => throw
return a map of `{:pred :id :body :type}` where `:type` is one of `:catch/default`, `:catch/type`, `:catch/raw`, `:catch/class`, `:catch/fn`(parse-clause expr)convert each form to the appropriate IR node
convert each form to the appropriate IR node
(parse-expr expr)IR node for anything before a (catch) or (finally)
IR node for anything before a `(catch)` or `(finally)`
(parse-finally-clause expr)IR node for (finally ...)
IR node for (finally ...)
(split-clauses clauses)We don't want to partition-by, we want to cleanly split into 3 chunks: expressions, catches, finallys. If expressions end up in the later ones, or finallys end up in the earlier ones, too bad. We'll rely on Clojure's built-in try/catch analyzer throw in that case.
We don't want to partition-by, we want to cleanly split into 3 chunks: expressions, catches, finallys. If expressions end up in the later ones, or finallys end up in the earlier ones, too bad. We'll rely on Clojure's built-in try/catch analyzer throw in that case.
(split-vec vec idx)Returns a vector of the given vec split at idx. If idx is nil, returns [vec nil].
Returns a vector of the given vec split at `idx`. If `idx` is `nil`, returns [vec nil].
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 |