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?