In some .NET libraries, there's a pattern of two alternative ways to call a function.
int i = x.GetValue(k); /* Might throw. */
if (x.TryGetValue(k, out int i) { /*...*/ } else { /* ... */ }
I don't like the names of these two functions as the not-Try variant presents itself the "normal" way to call a function. TryX, having the added word in the name, feels like a specialist form. For my new library that doesn't have to worry about existing users, I'd like to switch that around.
If I rename TryGetValue
to just GetValue
, what do I call the original GetValue
that will throw an exception if it can't complete my request?
Is there a standard name for this pattern? (I'm hoping the industry has an established pattern rather than coining a new word in the comments, but you're welcome to do so if you wish.)
EDIT: I could be persuaded that TryGetValue is the correct name, but I'd still like to change the name of GetValue that throws an exception, leaving no function called just GetValue.
GetValue()
method to explicitly call out the exception that might be thrown.