views:

358

answers:

2

What will happen in the following scenario? Will it throw work after response.redirect?

Or do I need to use Response.Redirect in catch block of main method where it throws exception call stack....

try
{    
//code
}
catch(Exception ex)
{    
Response.Redirect("Error.aspx");
throw;    
}
+6  A: 

Since you aren't supplying the parameter to indicate whether the current page should continue executing, it will automatically terminate the page by calling End(). Using the method with a single parameter is the same as calling the method with two parameters, with the second (endResponse) set to true. Since End() results in an exception being thrown, it won't ever reach your throw statement.

Reference: http://msdn.microsoft.com/en-us/library/a8wa7sdt.aspx

When you use this method in a page handler to terminate a request for one page and start a new request for another page, set endResponse to true or call the Redirect method overload. This method calls End for the original request, which throws a ThreadAbortException exception upon completion.

If you want the page to continue executing you need to use the signature with two parameters and set the endResponse parameter to false.

tvanfosson
+2  A: 

If you call Response.Redirect (without the overload) then it should immediately stop execution and so the throw won't be raised.

However, if you use the overload and pass in false eg. Response.Redirect("Error.aspx", false) then it will continue execution of the page and then redirect.

(At least, that is my understanding from the documentation).

Dan Diplo