有什么方法可以编写LINQ样式的“简写”代码,以遍历所有级别的抛出InnerException的异常?我宁愿就地编写它,而不是调用扩展函数(如下所示)或继承Exception
该类。
static class Extensions
{
public static string GetaAllMessages(this Exception exp)
{
string message = string.Empty;
Exception innerException = exp;
do
{
message = message + (string.IsNullOrEmpty(innerException.Message) ? string.Empty : innerException.Message);
innerException = innerException.InnerException;
}
while (innerException != null);
return message;
}
};