Try / Catch not catching System.Threading.ThreadAbortException in ReportDocument.ExportToHttpResponse

I am trying to export Crystal ReportDocument using ExportToHttpResponse as follows:

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

When I first tried to run this, I got a System.Threading.ThreadAbortException . After reading about how this is a known bug with ExportToHttpResponse in this question , I tried to implement the proposed solution for wrapping an operator in a try / catch block as follows:

 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 continue. However, I still get a System.Threading.ThreadAbortException in the closing bracket of the catch statement. My question is why the exception is still thrown, although I seem to catch it, and how can I fix it so that the exception is ignored?

+6
source share
1 answer

You can catch a ThreadAbortException and call the Thread.REsetAbort method to discard the exception throw. 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 turned out to be really useful to me in this regard.

+8
source

Source: https://habr.com/ru/post/925606/


All Articles