Application. threadexception + appdomain. currentdomain. unhandledexception

Source: Internet
Author: User
Static   Class  Program {  ///   <Summary>          ///  ApplicationProgram.  ///   </Summary>  [Stathread]  Static   Void  Main () {application. threadexception + =Application_threadexception; application. setunhandledexceptionmode (unhandledexceptionmode. catchexception); appdomain. currentdomain. unhandledexception + = Currentdomain_unhandledexception; application. enablevisualstyles (); application. setcompatibletextrenderingdefault (  False  ); Application. Run (  New  Mainform ());}  ///   <Summary>          ///  Handle unprocessed exceptions in the application domain (non-UI thread exceptions) ///   </Summary>          ///   <Param name = "sender"> </param>          ///   <Param name = "E"> </param>          Static   Void Currentdomain_unhandledexception ( Object  Sender, unhandledexceptioneventargs e ){  Try  {Exception ex = E. exceptionobject As Exception; MessageBox. Show (ex. Exception. Message );}  Catch  {}}  ///   <Summary>          ///  Unhandled application exception (ui thread exception)  ///   </Summary>          ///   <Param name = "sender"> </param>          ///   <Param name = "E"> </param>          Static  Void Application_threadexception ( Object  Sender, threadexceptioneventargs e ){  Try  {MessageBox. Show (E. Exception. Message );}  Catch  {}}} 

Note the following:CodeApplication. Run (New mainform (); only one application. Run code can be executed here, if you write the code as follows:

 
Application. Run (NewSplashscreenform (); application. Run (NewMainform ());

If an unhandled exception (ui exception or non-UI exception) occurs in mainform, the above exception handler cannot be captured.

 
 

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.