Try catch, Response.Redirect, and endResponse

 
Hi,

I get an error email from this aspx page once a while. I have pasted the code skeleton below. The error email says the error occured at the line marked *, where sproc1 is being called. When I look up the database table, I see the sproc2 has been executed as well. I created a test page and changing the endResponse parameter to true or false did not make any difference, when an exception occurs the execution always jumps straight to the catch block. I wish the same thing was happening in the production page as well, but the sproc2 is always being called.

try
{
    .....
    ...executing a db sproc1 *
    .....
    ...executing a db sproc2
    .....
}
catch(Exception e)
{
    ...senderroremail
    Response.Redirect("error.aspx....", false);
}

0
new2aspdotnet
9/14/2008 1:26:47 AM
asp.net.web-forms 93655 articles. 6 followers. Follow

1 Replies
450 Views

Similar Articles

[PageSpeed] 49

Looking at just the code you have listed, you are right. As soon as an exception is thrown in the try block the code jumps to catch block. Response.redirect won't make any difference in this case.

Are you sure that sproc2 is not called from some place else, or maybe from inside sproc1.

You have to do some more testing to figure this out. Try running the code at debug mode with break points at sproc1 and sproc2. Then put something in the sproc1 that will forcefully throw an error. On second thought why is it throwing an exception? What is the full exception message? Try adding throw new Exception("Debug Exception"); right after sproc1 and then see what happens (are both the procs still being called in this case?).


Remember to select "Mark as Answer" on the post that helped you find the solution!
0
matrixIII
9/14/2008 3:17:14 AM
Reply:

Similar Artilces:

try catch finally / response.redirect / response.end flow control question
Hi Guys, Can any one tell me if the finally block would be executed in the following example (assuming that dbReader.read() returned false because no records were found).   Many Thanks! DanielTry dbCon = New SqlConnection(myconnectionstring) dbCon.Open() dbCom = dbCon.CreateCommand() strSQL + "SELECT * FROM bookings WHERE ID > 9000" dbCom.CommandText = strSQL dbReader = dbCom.ExecuteReader() If dbReader.Read() Then 'init fields Else Response.Redirect("main.aspx") End if Finally dbReader.clo...

Try catch in web form
Hi I have a try catch in a (web form) method..now I want to implement a finally and in this check if there are any exceptions thrown .. if yes I have to do some processing in the finally block.  My question is how can I check in Finally if there are any exceptions been thrown at all . Thanks Exceptions that are thrown will be caught in the catch block, so that is where you will process your exceptions. Finally is used for things such as closing database connections and disposing of objects.Ryan OlshanASPInsider | Microsoft MVP, ASP.NEThttp://ryanolshan.comHow to ask a qu...

Try..Catch and Response.Redirect
I have sub that connect to a db to verify users. If the user is cleared the they are redirected to the next page and if not then they are forced to login again. I have noticed that during debug on my Try..Catch..Finally block an error is always fired on the resposne.redirect. Dim rs As SqlDataReader = objCMD.ExecuteReader If rs.Read() = False Then Response.Redirect("issuenewrga.aspx?OrderNum=" & txtOrderNum.Text & "&ItemNum=" & txtItemNum.Text & "&LineNum=" & txtLineNum.Text) ...

How do I do a try catch for web form?
Hi, I do this all the time for windows forms, and I put this code into the code behind for web forms and I get no errors, but it doesnt work, is there a way to do a try catch for asp.net web forms? I use vb.net code behind, thanks! Try Cmd.ExecuteNonQuery() Catch ex As Exception MsgBox("Error: " & ex.message) End Try You cant use MsgBox in ASP.NET.. thats a winform thingy.. Use javascript alert() instead. ...

web.config
I'm working an a SSO project.  On all of the sites, the forms login url is the login website. (login.mydomain.com), I'm redirected to the login page fine, but the ReturnUrl is just the page name, so if I'm on www.mydomain.com/Test.aspx, the ReturnUrl = /Test.aspx, not http://www.mydomain.com/Test.aspx.  I though an easy fix would be to catch this redirect in the global.asax and modify the url that I'm redirecting to for login, but I can't seem to find how to do it.  I'm also up for a better solution if someone has a tried and proven one.  Th...

Response.Redirect and Try Catch Finally
If I have a Try Catch Finally block with a Response.Redirect in the Catch and a Connection.Close in the Finally, will the code in the Finally still execute before the Redirect takes place? Someone asked a similar question at this web site: http://www.error-bank.com/microsoft.public.dotnet.languages.vb.1/190535_Thread.aspxDarrell Norton, MVPDarrell Norton's BlogPlease mark this post as answered if it helped you! Thanks for the link. Can anyone confirm that, yes, the Finally will execute? Yes,it will execute....

response.redirect inside a Try Catch...
I’ve come across a situation where I have a response.redirect inside a TRY Catch The redirect seams to trigger an exception.   I found a work around but I’m scared it might cause other problems.   Response.redirect(“blah blah”, False)    ß the false seams to help … although I’m not 100% sure why …   You guys see any problem in this solution?   It should be ok. The second argument means whether the execution of the current page should be stopped or not. When you specified false, it means if should not stop and thus no error otherwise previosly it...

try, catch, Response.Redirect problem
Hi,This is the code which makes me a problem: try{ Response.Redirect("SomePage.aspx");}catch{ ...someOperation():} It always goes to catch region...  i think you don't have that page in your web server. check it first.Got what you needed. Please mark as answer. This is a known issue, try to use the below code try {Response.Redirect("WebForm2.aspx",false);     }catch(Exception ex) { Response.Write(ex.Message); } HCHaissam Abdul MalakMCAD.NET| Blog | Sathesh_pandian:i think you don't have that page in your we...

Response.Redirect within Try Catch
Hi, I am using asp.net 2.0 and I have a page where I need to use the Try-Catch-Finally structure. Within the Try statement I have various commands and then at the end of it I have a Response.Redirect("....") to take the user to another page. Within my catch statement I also have a Response.Redirect("../errorPage.htm") which will take you to the error page if any exceptions occur. However, I have tested the page and I know there are no exceptions happening but the user is still getting redirected to the error page.  Is there anyway to make this not happen? I am using Smart Navigatio...

Implementing .Net Form into an APS.net web form, can this be done
I am new here, but have been searching for a while, and may not have the correct lingo to find what I am looking for.  I am tasked with implementing a .exe application that was writen vb6 then converted to .net into a new website my team is developing. The idea is to put each of the 3 different forms in this .exe application of 3 different .aspx pages. I have attempted multiple things to get this into the page and even started to just rewrite it as an ASP.net web form, but even then I can't reuse any of the code since the System.Web.UI.Page doesn't inherit the sa...

Response.Redirect inside a Try Catch block
Can you put a Response.Redirect inside a Try Catch block?I think you will get a thread Abored Error, true? Who said so? I just tried it and it worked fine!!!!What is mainly the problem you are facing?RegardsBilal Hadiar, MCP, MCTS, MCPD, MCTMicrosoft MVP - Telerik MVP...

Forms Authentication
Hi I am creating a new Website Application that redirects the logged in user to a webpage based upon the role to which he belongs programatically in 'Authentication' event. I have designed the app. so that a User can belong to a single role at one time and I am using membership provider.  I have a web page that is stored in the rootfolder which is accessible by all users(including unauthenticated users). This webpage contains different menuitems and one of them is 'login'.  So If user A belongs to Role 'abc', he is redirected to a webpage in folder abc. S...

web form
I have a web form with some text boxes with validation to ensure that data has been entered. I have two buttons one for "submit" and one for "Return to main". When I click on submit - all works OK as it should with asking the user to enter data for the text boxes. However, when I click "Return to main", instead of redirecting to the main page, the validation requirements for the form appear. Here is some of my code... <table> <tr> <td valign="top" style="width: 318px"><asp:TextBox id="txtTextBox1" runat=&quo...

Response.redirect without exception in a try catch?
I have these code: try{ if(!fuFaxnummer.PostedFile.FileName.EndsWith(".csv")){ Response.Redirect("faxnummerimport.aspx?ID=" + id + "&msg=2"); } //code to execute when the file is a .csv } catch (exception ex){ LogDA.insertLog(...); Response.Redirect("error.aspx"); }I know that "Response.Redirect" gives an Exception. When I set the bool endResponse at false (Response.redirect("",false)) there is no exception BUT he execute the code behind my IF(). Someone with a solution?      ...

Web resources about - Try catch, Response.Redirect, and endResponse - asp.net.web-forms

Resources last updated: 1/6/2016 5:59:28 PM