Ed_
Ed_

Reputation: 1117

Exception info from a ThreadAbortedException

I get an exception at response.redirect() and Visual Studio does not help me with appropriate info. I only get this for ex:expression cannot be evaluated, message:subprocess annulled and _HResult:-2146233040. I don't get a helplink or anything else.

  Try

        Dim unidadD As String = Request.QueryString("unity")
        Dim categD As String = Request.QueryString("category")
        Dim resulD As String = Request.QueryString("result")
        Dim anioD As String = Request.QueryString("year")
        Dim cicloD As String = Request.QueryString("cicle")

        Response.Redirect("~/Evaluacion/Detalle_Resultados.aspx?op=1" & "&unity=" & unidadD & "&category=" & categD & "&result=" & resulD & "&cicle=" & cicloD & "&year=" & anioD)


       Catch exa As System.Threading.ThreadAbortException
           Dim link As String = exa.HelpLink
        End Try

Upvotes: 0

Views: 465

Answers (2)

John Saunders
John Saunders

Reputation: 161801

Response.Redirect is expected to throw a ThreadAbortedException. Simply move the Response.Redirect out of the try/catch block.

Another option is to use:

Response.Redirect(url, False)

This will redirect without ending the current request. You can later call Application.CompleteRequest.

Another alternative would be

Try
    Response.Redirect(url)
Catch tax as ThreadAbortedException
    ' Do nothing, as this is an expected exception
    ' No need to rethrow, as this exception is automatically re-thrown
End Try

Upvotes: 1

James
James

Reputation: 82136

This is expected behaviour, as a workaround just pass false in Response.Redirect e.g.

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

Or as already suggested, get rid of the Try...Catch - not quite sure what you expect to do with a ThreadAbortException anyway...

Upvotes: 1

Related Questions