ThreadAbort Exception on Response.Redirect()

G

Guest

I am writing an ASP.NET application in which I am using the Response.Redirect() call. I noticed that I catch a ThreadAbort Exception after making the call. Indeed the documentation states that this occurs

"Beware! The run time can throw exceptions on its own! For example, Response.Redirect() throws a ThreadAbort exception. Even if you don't explicitly throw exceptions, you may use functions that do. Make sure you check Perfmon to get the real story, and the debugger to check the source.

What is the reason for this? What are the possible consequences of catching and then ignoring this exception? I find that control is passed to the new page

Thanks
Eagl
 
J

Jason DeFontes

In the case where you have:

Response.Redirect(...);
// more
// code
// here...

Redirect needs to end the request without executing any additional code,
and it does that by throwing an exception that the runtime catches
later. If you don't want it to do that you can use the optional second
parameter:

Redirect ( System.String url , System.Boolean endResponse )

which, if false, will keep it from throwing. But the exception itself is
by design, and harmless except for maybe a little overhead.

-Jason
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top