Avatar of brgdotnet
brgdotnet
Flag for United States of America asked on

Catching an exception in the Application_Error method.

I am looking for some good expert help on this question. I noticed that in the Global.asax file I have a method named Application_Error.
It is listed below. So it appears that we can catch all exceptions by using the Server.GetLastError() message. If that is the case, then why do we even need try catch blocks throughout the application? Couldn't we just use the Application_Error method to catch all of the exceptions?

void Application_Error(object sender, EventArgs e)
{
   Exception errorCaught = Server.GetLastError();
   Response.Redirect("~/Home/ErrorPage");

}
ASP.NET

Avatar of undefined
Last Comment
Miguel Oz

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Miguel Oz

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck