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!!
David Lozzi
Web Applications Developer
dlozzi@dotnet.itags.org.(remove-this)delphi-ts.comCatch the ThreadAbortException
Catch tae as System.Threading.ThreadAbortException
' ignore it.
Catch ex as Exception
' email the error
End Try
"David Lozzi" <DavidLozzi@.nospam.nospam> wrote in message
news:eTyw4PSHGHA.1032@.TK2MSFTNGP11.phx.gbl...
> 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!!
> --
> David Lozzi
> Web Applications Developer
> dlozzi@.(remove-this)delphi-ts.com
>
>
You can prevent this exception from being thrown by using the
overloaded version of Response.Redirect and passing False into the 2nd
parameter.
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
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com
"David Lozzi" wrote:
> 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!!
> --
> David Lozzi
> Web Applications Developer
> dlozzi@.(remove-this)delphi-ts.com
>
>
>
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment