If you log exceptions, watch out for Response.Redirect() – level 200

A common practice with any web application is to log fatal exceptions.  After all, if the user can’t complete the intended operation, wouldn’t you want to know about it?  I log all fatal exceptions in my apps because if one of these happens, I want to know about it so I can fix the bug.  Often, a production environment will uncover bugs in fringe use cases — bugs that would never turn up in the normal test cycle.  The exception information can help you reproduce and fix the bug.

Recently I employed the use of Response.Redirect( ) for a situation where I wanted to stop doing the work on the current page and go to another that was dependent on the query string.  I used Response.Redirect( ) for this, and my exception log started growing.  After investigation, I found that a ThreadAbortException was being thrown with every Response.Redirect( ) call.  By looking at the call stack, I discovered that Response.Redirect( ) actually calls Response.End( ) internally.  Response.End( ) throws the ThreadAbortException to terminate work on the current thread after sending the redirect message.