Application_Error - GetLastError () or GetLastError (). GetBaseException ()

When handling error in Application_Errorwhich of these two should I use?

I find several examples for both, but it is not entirely clear if one is better than the other. Are there cases where only one will show the correct error?

In addition, I doubt it matters, but the application uses MVC 4.

+5
source share
1 answer

It depends on what you need.

From the documentation of Exception.GetBaseException :

When overridden in a derived class, returns an exception that is the main cause of one or more subsequent exceptions.

Application_Error , , , , :

try {
   //Lots of code, method calls, etc...
   try {
       throw new FooException("Foo");
   } catch(FooException fe) {
       throw new BarException("Bar", fe);
   }
}catch(BarException be) {
    throw new FooBarException("FooBar", be);
}

GetLastError FooBarException, GetLastError().GetBaseException() FooException. , , .

, Foo, Bar FooBar GetLastError InnerException

+6

All Articles