什么是展示我的全部的正确方法InnerException
.
我发现我的一些InnerExceptions有另一个InnerException
,而且非常深入.
会InnerException.ToString()
做的工作,我还是我通过需要循环InnerExceptions
,建立一个String
有StringBuilder
?
关于重复。我可以访问该
Message
属性,但不能访问该属性,Detail
即使在调试期间我可以看到它是 Exception 对象的一部分。所以问题是为什么不能访问Detail
财产。
我捕捉到一个异常。
catch (Exception ex)
{
string msg = ex.InnerException.InnerException.Message;
// say Exception doesnt have Detail property
// string detail = ex.InnerException.InnerException.Detail;
return Json(new { status = "Fail", message = msg, detail: detail });
}
Run Code Online (Sandbox Code Playgroud)
例如.InnerException.InnerException。终于有一些真实的消息,"db table duplicated key"
ex.InnerException.InnerException.Message我可以得到消息。
但是"the guilty key"
即使有一个属性也无法获得详细信息Detail
InnerException
两次才能获得一些有意义的信息?