在ReportDocument.ExportToHttpResponse中尝试/捕获不捕获System.Threading.ThreadAbortException

时间:2022-10-28 14:28:29

I am trying to export a Crystal ReportDocument using ExportToHttpResponse like so:

我试图使用ExportToHttpResponse导出Crystal ReportDocument,如下所示:

report.ExportToHttpResponse(exportOptions, HttpContext.Current.Response, true, "test");

When I first tried to run this, I received a System.Threading.ThreadAbortException. After reading about how this is a known error with ExportToHttpResponse in this question, I tried implementing the suggested workaround of wrapping the statement in a try/catch block like so:

当我第一次尝试运行它时,我收到了System.Threading.ThreadAbortException。在这个问题中阅读了有关ExportToHttpResponse的已知错误之后,我尝试实现了在try / catch块中包装语句的建议解决方法,如下所示:

try
{
    report.ExportToHttpResponse(expOptions, HttpContext.Current.Response, true, "test");
}
catch (System.Threading.ThreadAbortException e)
{
}

As I understand it, this should catch and ignore the error, and proceed. However, I am still getting the System.Threading.ThreadAbortException on the closing bracket of the catch statement. My question is why is the exception still being received even though I am apparently catching it, and how could I go about fixing it so that the exception is ignored?

据我了解,这应该捕获并忽略错误,然后继续。但是,我仍然在catch语句的结束括号上获得System.Threading.ThreadAbortException。我的问题是为什么即使我显然正在捕获异常仍然被接收,我怎么能去修复它以便忽略异常?

1 个解决方案

#1


8  

You can catch the ThreadAbortException and call the Thread.REsetAbort method, to cancel the bubbling of the exception. However, keep in mind that response.end is a bad idea. Whenever you can try to call HttpApplication.CompleteRequest(), and read this SO question which proved really useful to me in this regard.

您可以捕获ThreadAbortException并调用Thread.REsetAbort方法,以取消异常的冒泡。但是,请记住,response.end是个坏主意。每当你可以尝试调用HttpApplication.CompleteRequest(),并阅读这个在这方面对我来说真正有用的问题。

#1


8  

You can catch the ThreadAbortException and call the Thread.REsetAbort method, to cancel the bubbling of the exception. However, keep in mind that response.end is a bad idea. Whenever you can try to call HttpApplication.CompleteRequest(), and read this SO question which proved really useful to me in this regard.

您可以捕获ThreadAbortException并调用Thread.REsetAbort方法,以取消异常的冒泡。但是,请记住,response.end是个坏主意。每当你可以尝试调用HttpApplication.CompleteRequest(),并阅读这个在这方面对我来说真正有用的问题。

相关文章