gpt4 book ai didi

c# - Try/Catch 未在 ReportDocument.ExportToHttpResponse 中捕获 System.Threading.ThreadAbortException

转载 作者:太空狗 更新时间:2023-10-29 21:23:36 25 4
gpt4 key购买 nike

我正在尝试使用 ExportToHttpResponse 导出 Crystal ReportDocument,如下所示:

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

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

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

据我了解,这应该会捕获并忽略错误,然后继续。但是,我仍然在 catch 语句的右括号中收到 System.Threading.ThreadAbortException。我的问题是,为什么即使我显然正在捕获它,仍然会收到异常,我该如何修复它以便忽略异常?

最佳答案

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

关于c# - Try/Catch 未在 ReportDocument.ExportToHttpResponse 中捕获 System.Threading.ThreadAbortException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12465967/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com