Whether to check for null
Posted
by coffeeaddict
on Stack Overflow
See other posts from Stack Overflow
or by coffeeaddict
Published on 2010-03-24T19:53:23Z
Indexed on
2010/03/24
20:03 UTC
Read the original article
Hit count: 149
c#
|error-handling
I know that you should always check incoming params to a method for null. But what if I have this scenario with a try/catch referring to a local variable. Do I really need to check for null below? Because it's gonna catch it anyway if it's null and the next line of code tries to use the refundResponse variable:
public string DoRefund(...)
{
try
{
......
string refundTransactionID = string.Empty;
......
RefundTransactionResponseType refundResponse = transaction.DoRefund(...);
if (refundResponse != null)
refundTransactionID = refundResponse.RefundTransactionID;
.....
}
catch (Exception ex)
{
LogError(ex);
return ex.ToString();
}
}
© Stack Overflow or respective owner