How to use Response.End () in a try Catch

Source: Internet
Author: User
Tags try catch

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.