Unhandled exception in C #)

Source: Internet
Author: User
An unhandled exception is always encountered during C # development. You can call the Appliaction. threadexcetpion () event to handle this exception.

This method is very simple to use and highly efficient. developers can easily add other functions for exception handling.

Static void main ()
{
Application. threadexception + = new threadexceptioneventhandler (application_threadexception );
Application. Run (New form1 ());
}
Private Static void application_threadexception (Object sender, threadexceptioneventargs E)
{
MessageBox. Show (E. Exception. tostring ());
}

However, this method also has limitations, that is, it can only handle unhandled exceptions in the main thread. If unhandled exceptions occur on other threads, the above method will not be able to handle them. In this case, appdomain. unhandledexception can be used to replace application. threadexception.

In this case, the exception of other working threads must still be called by the main thread. The abnormal break implementation in the working thread can be called by the main thread to determine the invokerequired attribute of the control first, when this parameter is set to true, the invoke method of the control of the main thread is called to call it.

This article is a master in the blog Park. Unfortunately, I forgot the address. Sorry, I hope the author can see it !!!

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.