Handle exceptions from within the closures

Right now we just wrap the entire thing in a try…catch.

We do this by changing the generated template.

See #61.