When Response.End () is called, the Thread.CurrentThread.Abort () operation is performed.
If Response.End () is placed in the Try...catch, the catch captures the System.Threading.ThreadAbortException of the exception produced by Thread.CurrentThread.Abort ().
Workaround (Choose one of the following):
1. Exclude the ThreadAbortException exception from the catch, the sample code is as follows:
Try
{
Response.End ();
}
catch (System.Threading.ThreadAbortException)
{
}
catch (Exception ex)
{
Response.Write (ex);
}
2. End the current request with Context.ApplicationInstance.CompleteRequest (), with the following code:
protected void Page_Load (object sender, EventArgs e)
{
Try
{
Response.Write ("Hello world!");
This. Page.visible = false;
Context.ApplicationInstance.CompleteRequest ();
}
catch (Exception ex)
{
Response.Write (ex);
}
}
How to use Response.End () in a try Catch