Skip to content

Instantly share code, notes, and snippets.

@lgolubyev
Created Jul 11, 2022
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