Skip to content

Instantly share code, notes, and snippets.

@einarwh
Last active Aug 29, 2015
Embed
What would you like to do?
var catchers = new [] {
Encapsulate((ArgumentException x) => x.Message),
Encapsulate((InvalidOperationException x) => { Log(x.Message); throw x; },
Encapsulate((NullReferenceException x) => "Uh oh")
};
var protect = catchers.Aggregate((acc, nxt) => thing => nxt(acc(thing)));
var f = protect(() => FetchStringSomewhere());
var s = f();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment