Skip to content

Instantly share code, notes, and snippets.

@lgolubyev
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
Embed
What would you like to do?
var exceptionTrappingLazy = new Lazy(() => CallExternalService());
try{
// 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 {...}
try
{
//Accesing the Value property again won't call CallExternalService()
//It will throw the trapped exception again!
var lazyValueAgain = exceptionTrappingLazy.Value;
}
catch{...}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment