Exception handling in the Global.asax.cs file

I am maintaining an Asp.net web application. Instead of using try catch blocks in the C# code to wrap specific C# logic they put this exception handling code in the global.asax file.

Exception exception = server.GetLastError();
if(exception != null)
  exception = exception.GetBaseException()
  if(exception ! = null)
      zError.InnerHtml = exception.Message();
        // Code not shown here but write the error message to the exception log.

In my mind this seems a little less effective than using try catch blocks throughout the code in order to target a specific exception. Like for example suppose a SQLException occured. My thinking is that the above code would not log this as a sqlException, but as some more general type of exception. Am I correct in my thinking? What do other Experts thing about this?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Göran AnderssonCommented:
You should combine both ways of handling excpetions. Catch exceptions in the code that you expect and can handle, and leave the unexpected and unrecoverable exceptions to the fallback handling in the global.asax.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
brgdotnetcontractorAuthor Commented:
Dear GreenGhost. You have helped me before and I deeply appreciate your  expert help becuase you give excellent information.

Your reply sounds good. If we were to be more specific though, am I correct in my thinking that the exception caught in the global asax file for the code I posted is not as specific as if I were to put
in specific catch code to catch a specific exception such as a SqlException,OutOfMemoryException,ArithmeticException etcetera?
Göran AnderssonCommented:
Yes, when catching exceptions close to the source, you would want to catch only the specific exceptions that you expect.

If you for example do a database call, you would only catch SqlException. If a totally different exception would somehow occur in that code, you wouldn't want to handle it as if it was an error message from the database. You should let that exception go to be handled by the code in global.asax, so that it's logged as an unexpected error.
brgdotnetcontractorAuthor Commented:
Thank you.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.