scgilardi/slingshot — pull request #34 by dlowe (2013-03-24 08:31:52+00:00)
Title: add try+/else

This patch adds an optional 'else' clause to try+ (and very good test coverage of the feature). The idea is [stolen from python](http://docs.python.org/2/tutorial/errors.html#handling-exceptions). It is a surprisingly useful construct, in my experience, and I'd love to have it in clojure :)

The basic goal is to make it easier to avoid over-catching exceptions. I had this bug in my code, recently:

```
(try+
(do-something!)
(tell-someone!)
(catch Object e
(requeue-do-something!)))
```

... when (tell-someone!) threw, it caused (do-something!) to be erroneously requeued. Without a try+/else construct, I wound up hacking something like:

```
(let [threw? (atom false)]
(try+
(do-something!)
(catch Object e
(reset! threw? true)
(requeue-do-something!))
(when-not @threw?
(tell-someone!)))
```

With a try+/else construct, I'd have the much clearer:

```
(try+
(do-something!)
(catch Object e
(requeue-do-something!))
(else
(tell-someone!)))
```

Hope you'll consider the patch!