scgilardi / slingshot

Enhanced try and throw for Clojure leveraging Clojure's capabilities
654 stars 28 forks source link

Compatibility with raw ExceptionInfo objects #35

Closed gfredericks closed 10 years ago

gfredericks commented 11 years ago

I found myself wishing I could use slingshot only at the catch site -- i.e., do something like:

(throw (ex-info "Hoo ha" {:foo 8}))

and then somewhere else:

(try+ (code)
  (catch [:foo 8] _ :oops))

I'm inclined to this usage because ex-info feels like the more idiomatic thing to do, but I don't think there's any easy way (without slingshot) to catch ExceptionInfo based on the data.

Based on some cursory repl-play, I would think this should be possible to support in a backwards compatible way by applying the selectors to the :object if the ExceptionInfo was thrown by throw+ (as detected by the metadata) or to the top-level map otherwise.

If this seems reasonable I'd be happy to take a stab at it myself.

scgilardi commented 10 years ago

Thanks for the suggestion. I'm sorry it took so long for me to reply. I like the idea. I did an implementation in https://github.com/scgilardi/slingshot/pull/47 . I'd appreciate hearing any thoughts you have if you're willing to review it.

gfredericks commented 10 years ago

This looks good, thanks!

In the interim I've been using catch-data which I think ended up being a lot simpler since it didn't have to support older versions of Clojure.

scgilardi commented 10 years ago

you're welcome! catch-data looks nice. closing this issue along with the merge of #47.