Geeks With Blogs

AzamSharp Some day I will know everything. I hope that day never comes.
Most of you already know this but those who don't here it is. If you want to redirect to some page in the catch block you will have to supply the second parameter of Response.Redirect method. Something like this:

try { 

// Do some dirty work

}

catch(Exception ex) 

{ 

Response.Redirect("Failure.aspx",false); 


}


Also consider this situation. This will also throw an exception "Thread is being aborted". The reason is the parent try-catch block. You are redirecting in the try block without using the second parameter of the Response.Redirect method. You can solve this problem by only keeping the try-catch block in the SomeMethod() method also you can redirect in the parent catch block which will work fine.

try 
{

SomeMethod();  

}

catch(Exception ex) 
{



}

public void SomeMethod() 
{

try
{  

	// Some funky stuff

}

catch(Exception ex) 
{
	

}

Response.Redirect("Success.aspx"); 

}
Posted on Thursday, July 14, 2005 12:03 PM | Back to top


Comments on this post: Redirection in the Catch Block

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Mohammad Azam | Powered by: GeeksWithBlogs.net