Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

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:

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?

like image 321
jaredk Avatar asked Sep 17 '12 19:09

jaredk


1 Answers

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.

like image 134
Carlos Grappa Avatar answered Sep 27 '22 17:09

Carlos Grappa