When handling an error in Application_Error
, which of those two should I use?
I'm finding multiple examples for both, but it's not really clear if one is better than the other. Are there cases where only one will show the correct error?
Also, I doubt this matters, but the application is using MVC 4.
It depends on what exactly do you need.
From the documenation of Exception.GetBaseException:
Application_Error
handles exceptions on the upper level, maybe after several exception handling mechanisms, so if exception is thrown like this:then
GetLastError
will get youFooBarException
, whileGetLastError().GetBaseException()
will get youFooException
. So the former returns actual unhandled exception while the latter returns the root cause.I assume that Foo, Bar and FooBar exception classes do not override
GetLastError
orInnerException