How do I shorten these if else statements? As you can see, those elses are repeated.
if (exception.InnerException != null)
{
if (!string.IsNullOrEmpty(exception.InnerException.Message))
{
errorMessage = exception.InnerException.Message;
}
else if (!string.IsNullOrEmpty(exception.Message))
{
errorMessage = exception.Message;
}
else
{
errorMessage = exception.ToString();
}
}
else if (!string.IsNullOrEmpty(exception.Message))
{
errorMessage = exception.Message;
}
else
{
errorMessage = exception.ToString();
}
string.IsNullOrWhiteSpaceinstead ofstring.IsNullOrEmpty, just to counter those edge cases where any other white-space character was used instead of an empty string. \$\endgroup\$