Ensure a transaction is closed if the yielded block raises an exception.

If the yielded block raises an exception the connection is in a broken state, with a connection open and the (should be temporary) cursor still open.
This fixes that.
(Nice plugin btw!)