scgilardi / slingshot

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

provide optional argument to throw+ to allow specifying the cause explicitly, addresses issue #29 #48

Closed scgilardi closed 10 years ago

scgilardi commented 10 years ago

previously the cause was automatically captured within a try+ catch clause or nil otherwise.

This could also be accomplished by allowing more flexibility in the throw+ arguments, but that's quite a bit more complicated to code.

pjstadig commented 10 years ago

Instead of with-cause how about introducing a rethrow+ form with the following arities ([cause] [cause object] [cause object message] [cause object fmt & args])?

scgilardi commented 10 years ago

Looking over the docs at http://docs.oracle.com/javase/7/docs/api/java/lang/Throwable.html , I think rethrow doesn't have quite the right connotation. It's more like consing something new onto the cause chain or "wrapping" which is already used a fair amount in slingshot docs for the relationship between the ExceptionInfo object and the context being thrown.

I took another shot at allowing an optional cause argument and I think the result is good.

(throw+ object cause? message-or-fmt? & fmt-args)

I like it better than with-cause or a separate rethrow+.