我有以下代码:
protected string formatException(Exception e)
{
var exError = "<form>";
if (e == null)
{
throw new ArgumentNullException("e");
}
exError += "<fieldset><legend><a href='#'>" +
"<span class='show-expanded'>collapse message</span>" +
"<span class='show-collapsed'>expand message</span>" +
"</a></legend><p>" + e.Message + "</p></fieldset>";
exError += "<fieldset><legend><a href='#'>" +
"<span class='show-expanded'>collapse trace</span>" +
"<span class='show-collapsed'>expand trace</span>" +
"</a></legend><p>" + e.StackTrace + "</p></fieldset>";
if (e.InnerException != null)
{
// same functionality but for the inner exception and the InnerException.InnerException
}
return exError + "</form>";
}
调用时,它会格式化异常消息。但是我想让它包括InnerException
和InnerException.InnerException
有什么方法可以递归地执行此操作,还是将消息格式放在另一个函数中并调用它会更好?