Skip to content

Instantly share code, notes, and snippets.

@einarwh
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save einarwh/0f4df51ff874f322e092 to your computer and use it in GitHub Desktop.
Save einarwh/0f4df51ff874f322e092 to your computer and use it in GitHub Desktop.
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