【问题标题】:Exception info from a ThreadAbortedException来自 ThreadAbortedException 的异常信息
【发布时间】:2013-10-14 12:09:05
【问题描述】:

我在 response.redirect() 处遇到异常,并且 Visual Studio 无法帮助我提供适当的信息。我只为ex:expression cannot be evaluatedmessage:subprocess annulled_HResult:-2146233040 得到这个。我没有获得帮助链接或其他任何内容。

  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

【问题讨论】:

  • 致电exa.ToString() 获取解决问题所需的一切。
  • 看起来你只是在调试器的某个地方输入了错误的异常名称(ex 而不是 exa)
  • 乔尔你可以使用任何变量名

标签: asp.net vb.net exception exception-handling


【解决方案1】:

Response.Redirect 预计会抛出 ThreadAbortedException。只需将 Response.Redirect 移出 try/catch 块即可。

另一种选择是使用:

Response.Redirect(url, False)

这将重定向而不结束当前请求。您可以稍后致电Application.CompleteRequest

另一种选择是

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

【讨论】:

  • 好吧,所以不需要在 try/catch 块中放入 response.redirect 语句吗?我总是把所有东西都放在里面
  • 或者使用Response.Redirect(url, False),或者你可以使用Catch tax As ThreadAbortException'Do nothingEnd Try
【解决方案2】:

这是expected 的行为,作为一种解决方法,只需在Response.Redirect 中传递false,例如

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

或者正如已经建议的那样,摆脱Try...Catch - 不太确定你希望用ThreadAbortException 做什么......

【讨论】:

  • 我添加了该异常,试图在一般异常未提供足够信息后获取更多信息。是否存在一个列表说明为什么会出现一些异常?
猜你喜欢
  • 2011-09-14
  • 2019-07-14
  • 2018-12-01
  • 2016-03-15
  • 2022-01-02
  • 1970-01-01
  • 2019-11-06
  • 2011-12-12
  • 1970-01-01
相关资源
最近更新 更多