Skip to content

Instantly share code, notes, and snippets.

Created July 11, 2022 14:58
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
var exceptionTrappingLazy = new Lazy(() => CallExternalService());
// Accessing the Value property will execute CallExternalSe4rvice()
// Now, imagine that the external service is down
// The call to CallExternalService() throws an exception
var lazyValue = exceptionTrappingLazy.Value;
catch {...}
//Accesing the Value property again won't call CallExternalService()
//It will throw the trapped exception again!
var lazyValueAgain = exceptionTrappingLazy.Value;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment