Wrapping failures

Wrap the failure value, if any, with the given function. This is
useful in particular when you want all the exceptions returned from a
certain library to be of a certain type, even if they were generated by
a different library.