1

I work on a rather large web site. We currently have 4 web servers and an active passive db cluster running ASP.NET 2.0 with C#. Currently our exception handling is not trapping the correct exception being thrown. I have heard it is because Server.GetLastError() is not thread safe (note: we currently do not use Server.GetLastError().GetBaseException() which might be why we are not getting the correct error).

We are starting a project to trap exact exceptions so we can actually see the root cause of the error and I’m trying to find the best way to do it.

Our options are:

  • Go through all of our classes/methods(hundreds, if not thousands) to add try/catch/finally blocks to trap the correct exception.
  • Figure out a way to properly handle the exceptions in the global.asax.

So I guess my questions are:

  • Is Server.GetLastError() thread safe?
  • If two exceptions are thrown at the same time, will both be logged?
  • Is there a better way to handle this than what I have listed?

2 Answers 2

1

I believe that you should not alter the initial application at all. You should create and register at web.config an IHttpModule that hooks on Error event to log recursively the exception thrown and it's inner exceptions.

Further Reading:

Sign up to request clarification or add additional context in comments.

3 Comments

How is this different than the application_error method in Global.asax?
Well it isn't but consider the following points fuchangmiao.blogspot.com/2008/03/globalasax-vs-httpmodule.html before making a decision.
this solution is good unless you want to redirect, which modules do not handle well; there is a work-around, though it's convoluted; see blogs.microsoft.co.il/blogs/oshvartz/archive/2008/05/17/…
0

You should take a look at Steven A. Lowe's CALM product.

It's a really nice 'plug-in' solution.

(Disclaimer: I was one of the beta-testers)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.