Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Response.Redirect gens ThreadAbortException that's either not being caught or thrown a second time.

Reply
Thread Tools

Response.Redirect gens ThreadAbortException that's either not being caught or thrown a second time.

 
 
Eric
Guest
Posts: n/a
 
      08-19-2005
I have the following situation: I was getting intermittent errors using
Reponse.Redirct("url", true) and was trying to catch the
ThreadAbortException, but it was not staying caught and was showing up again
where my code wasnt expecting it. I'm not sure what was causing it. The
catch block in RedirectPage is supposed to quash the ThreadAbortException
but it not only shows up there, but also in the outer catch block will catch
it as well. It should not show up in both places.

For example
try 'Outer
'Do stuff
'want to catch an exception on a specific action
try
Throw new Exception("test")
catch ex as Exception
RedirectPage("Error.aspx")
End Try

catch tex as TreadAbortException
'This should never fire as the RedirectPage function catches it. But
it's showing up after the RedirectPage catches a ThreadAbortException
already
catch ex as exception
'should be only something not handled previously.
End Try


Public sub RedirectPage(url as string)
Dim strMsg As String
Try
Response.Redirect(url, TRUE)
Catch tex As Threading.ThreadAbortException ' this is SUPPOSED to
catch the threadAbort if true is passed in, but it doesnt always
strMsg = tex.Message
Catch ex As Exception
strMsg = ex.Message
End Try

End Sub


 
Reply With Quote
 
 
 
 
=?Utf-8?B?Q293Ym95IChHcmVnb3J5IEEuIEJlYW1lcikgLSBNVlA=?=
Guest
Posts: n/a
 
      08-19-2005
I am not surprised you are bubbling up Response.Redirect errors. There is an
easy way around it.

In your catches set some booleans instead of Response.Redirect. You can then
create an if block to determine where to send the person:

If (pageInError) Then
Response.Redirect("Error.aspx")
Else If ....

etc.

Do not have any work after this block. You should have already answered the
question of whether you are redirecting and where by this time.

Why the error? It is simple. You are sending out a Response.Redirect to the
client, which makes the client request the new page. Any code after the
redirect should not be run, so the thread answering THIS PARTICULAR request
has to abort. If the last action is the Redirect, you get around this issue.
It is all in the ordering.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***************************
Think Outside the Box!
***************************


"Eric" wrote:

> I have the following situation: I was getting intermittent errors using
> Reponse.Redirct("url", true) and was trying to catch the
> ThreadAbortException, but it was not staying caught and was showing up again
> where my code wasnt expecting it. I'm not sure what was causing it. The
> catch block in RedirectPage is supposed to quash the ThreadAbortException
> but it not only shows up there, but also in the outer catch block will catch
> it as well. It should not show up in both places.
>
> For example
> try 'Outer
> 'Do stuff
> 'want to catch an exception on a specific action
> try
> Throw new Exception("test")
> catch ex as Exception
> RedirectPage("Error.aspx")
> End Try
>
> catch tex as TreadAbortException
> 'This should never fire as the RedirectPage function catches it. But
> it's showing up after the RedirectPage catches a ThreadAbortException
> already
> catch ex as exception
> 'should be only something not handled previously.
> End Try
>
>
> Public sub RedirectPage(url as string)
> Dim strMsg As String
> Try
> Response.Redirect(url, TRUE)
> Catch tex As Threading.ThreadAbortException ' this is SUPPOSED to
> catch the threadAbort if true is passed in, but it doesnt always
> strMsg = tex.Message
> Catch ex As Exception
> strMsg = ex.Message
> End Try
>
> End Sub
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
'unreported exception java.io.IOException; must be caught or declared to be thrown Cassandra Java 0 10-08-2009 06:40 AM
Thrown exception doesn't get caught where it "should." Chris C++ 7 01-25-2007 05:52 PM
Exception thrown by webservice and caught by ASP.NET application Mark ASP .Net 1 04-04-2006 03:46 PM
how to get the line number where error was thrown and/or caught Mark Kamoski ASP .Net 5 09-19-2003 10:46 PM
Exceptions thrown in includes not caught Martin Plechsmid ASP General 9 08-03-2003 10:18 AM



Advertisments