Every now and again, we get a question in the newsgroup asking why they are getting a ThreadAbortException. Code is provided, and 99% of the time a Response.Redirect is always the culprit.
I've answered this atleast 10 times without really thinking about it - though I always make sure to give a thorough explanation. (I just woke up, but i'm pretty sure it's REsponse.End() that throws the exception, which is called internally by Response.Redirect()).
Today though, for some reason, it seems really wrong that Response.Redirect throws an exception. What's worse is that one of the overloads, Response.Redirect(string path, bool end); doesn't. I see two problems here. First of all, it really isn't an exception situtation? People call Response.End() and Response.Redirect() all the time - heck, they are public functions! You are guaranteed that calling these public functions will result in an exception - doesn't seem right.
The 2nd problem is that an overload of Response.Redirect() doesn't generate an exception. Obviously it's alright for overloads to behave differently, for example:
public static DoSomething(Page page)
{
}
public static DoSomething()
{
if (HttpContext.Current == null || !(HttpContext.Current.Handler is Page)
{
//throw exception..
}
DoSomething(HttpContext.Current.Handler);
}
But for one of them to _always_ throw an exception just seems wrong (reading over that I'm not sure there's a difference between my 1st point and my 2nd point, but whatever)...
I imagine the reason the exception is thrown is for some deep design reason needed by the ASP.NET framework. Insight would be welcomed...
Posted
Thu, May 18 2006 8:05 AM
by
karl