This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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