How about new syntactical sugar for exception checking?
The Lounge
42
Posts
27
Posters
1
Views
1
Watching
-
;)
cheers Chris Maunder
-
We get a shiny new "?" operator that takes
string result = null;
if (field != null)
{
result = field.Value;
}and converts this to
string result = field?.Value
So what about the case where we're handling a flaky API
string result = null;
try
{
result = DodgyApi.GetValue(); // may throw an exception
}
catch
{
result = null;
}What would you suggest we do for that? What about a headasplode (*) operator
string result = DodgyApi.GetValue*();
where
GetValue*
will silently swallow the exception thrown byGetValue
and returndefault
. Or am I setting a new standard for lazy, shameful programming here this hot, lazy afternoon?cheers Chris Maunder