Last active
December 20, 2016 02:21
-
-
Save jdunne/3819c4903f3f6239bbeb3a6ae123ac7c to your computer and use it in GitHub Desktop.
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
// One solution is to pass a default value into the method. | |
string uri = configFile.GetValueOrDefault(“serviceUri”, | |
“http://example.com/service"); | |
ConnectToService(uri); | |
// Another possibility is to introduce a Maybe type to hold the return value. | |
Maybe<string> uri = configFile.GetValue(“serviceUri”); | |
if(uri.HasValue) | |
{ | |
ConnectToService(uri.HasValue ? | |
uri.Value : | |
“http://example.com/service"); | |
} | |
// If a missing return value is highly unlikely or | |
// there can be no default handling of a missing value, | |
// an exception can be thrown. | |
try | |
{ | |
ConnectToService(configFile.GetValue(“serviceUri”)); | |
} | |
catch(MissingConfigurationException exception) | |
{ | |
// handle the error | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment