Tuesday, July 24, 2018
Try Catches are not necessary for logging exceptions
I support a large system where there are try catches everywhere to log the exception. See my post Simple and secure exception handling for .NET web applications for a better way. I found an instance where instead of just removing the (unnecessary) try catch, I simply removed the line that logged the error and then threw the exception expecting the Application_Error event to log. Unfortunately, the stack trace that was logged only indicated the line number of the Throw statement and not where the error actually occurred! The lesson is, if you use a try catch, then log it right there. If not, just get rid of the try catch completely.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment