Thread was being aborted

D

David Lozzi

Howdy,

I have an error mod in my app that emails me whenever there is an error. I
use try..catch to capture the error. It works great, I love it, except for
this one minor issue. Whenever there is a script that processes some data
then issues a response.redirect() I get "Thread was being aborted" emailed
to me. Below is an example of a script of where the error is occuring. It
doesn't affect the end user at all, but I just keep getting the emails and
I'm going live with this today, which means more emails :(

Try
sqlconn.Open()
If sqlcomm.ExecuteNonQuery > 0 Then
lblError.Text = ""
sqlconn.Close()
Response.Redirect("eventhotels.aspx?EID=" & EID)
Else
sqlconn.Close()
lblError.Text = EmailError("eventhoteladd", "savehotel",
"nothing to update.")
End If
Catch ex As Exception
sqlconn.Close()
lblError.Text = EmailError("eventhoteladd", "savehotel",
ex.Message)
End Try

I tried putting the sqlconn.close into the finally statement but still for
the same results.

Thanks!!
 
S

Sql Agentman

Catch the ThreadAbortException

Catch tae as System.Threading.ThreadAbortException
' ignore it.
Catch ex as Exception
' email the error
End Try
 
K

KJ

You can prevent this exception from being thrown by using the
overloaded version of Response.Redirect and passing False into the 2nd
parameter.
 
G

Guest

You are getting this exception because the Response.Redirect method
internally calls Response.End,which raises this exception and the page
processing terminates. Response.End raises the exception indirectly through
calling Thread.Abort. Move the redirect to outside of the Try block, and use
the "false" overload of Response.Redirect method:


Instead of putting Response.Redirect into a Try..Catch block. You may try
this one:

Dim redirect as Boolean =False;
Try
sqlconn.Open()
If sqlcomm.ExecuteNonQuery > 0 Then
lblError.Text = ""
sqlconn.Close()

Else
sqlconn.Close()
lblError.Text = EmailError("eventhoteladd", "savehotel",
"nothing to update.")
End If
Catch ex As Exception
sqlconn.Close()
lblError.Text = EmailError("eventhoteladd", "savehotel",
ex.Message)
End Try
If Redirect Then Response.Redirect("eventhotels.aspx?EID=" & EID, False)



--Peter
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top