Problem: How to display exception detail (InnerException?) in my DbError view in MVC3
The code below produces a null reference when trying to display the InnerException.
<p>@Model.Exception.GetType().Name<br />
@Model.Exception.InnerException.Message.ToString()<br /> <!-- null reference! -->
thrown in @Model.ControllerName @Model.ActionName</p>
In my global.asax
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute
{
ExceptionType = typeof(DbException),
// DbError.cshtml is a view in the Shared folder.
View = "DbError",
Order = 2
});
code originally from http://community.codesmithtools.com/CodeSmith_Community/b/tdupont/archive/2011/03/01/error-handling-and-customerrors-and-mvc3-oh-my.aspx
Not all exceptions have an inner one. Make sure that the provided exception actually has an
InnerException. If it doesn’t, simply print out the details of the provided exception instead (which you generally should do, theInnerExceptionsimply details the error mentioned in the root exception).