WinForm C # Global Error capture Processing "grooming"

Source: Internet
Author: User

1   Static class Program2     {3         /// <summary>4         ///The main entry point for the application. 5         /// </summary>6 [STAThread]7         Static voidMain ()8         {9             TryTen             { One  A                 //add an exception that is not caught by the event handler - Application.setunhandledexceptionmode (unhandledexceptionmode.catchexception); -                 //add event handling UI thread exception theApplication.ThreadException + =NewSystem.Threading.ThreadExceptionEventHandler (application_threadexception); -                 //Add event handling non-UI thread exception -AppDomain.CurrentDomain.UnhandledException + =NewUnhandledexceptioneventhandler (currentdomain_unhandledexception); -  +  - application.enablevisualstyles (); +Application.setcompatibletextrenderingdefault (false); AApplication.Run (Newfrmactivity ()); at             } -             Catch(Exception ex) -             { -                 stringstr =""; -                 stringStrdateinfo ="An unhandled exception occurred with the application:"+ DateTime.Now.ToString () +"\ r \ n"; -  in                 if(Ex! =NULL) -                 { tostr =string. Format (Strdateinfo +"Exception Type: {0}\r\n exception message: {1}\r\n exception information: {2}\r\n", + Ex. GetType (). Name, ex. Message, ex. StackTrace); -                 } the                 Else *                 { $str =string. Format ("Application Thread error: {0}", ex);Panax Notoginseng                 } -  the                 //Write Log + Writelog.writeerrlog (str); AMessageBox.Show ("A fatal error occurred, please contact the author in time! ","System Error", MessageBoxButtons.OK, messageboxicon.error); the             } +  -         } $  $         /// <summary> -         ///This is how we deal with unhandled exceptions, many of which can be done by logging the error details to the text, the database, sending an error message to the author's mailbox or re-initializing it after an error, and so on. -         /// </summary> the         /// <param name= "Sender" ></param> -         /// <param name= "E" ></param>Wuyi         Static voidApplication_threadexception (Objectsender, System.Threading.ThreadExceptionEventArgs e) the         { -  Wu             stringstr =""; -             stringStrdateinfo ="An unhandled exception occurred with the application:"+ DateTime.Now.ToString () +"\ r \ n"; AboutException error = E.exception asException; $             if(Error! =NULL) -             { -str =string. Format (Strdateinfo +"Exception Type: {0}\r\n exception message: {1}\r\n exception information: {2}\r\n", - error. GetType (). Name, error. Message, error. StackTrace); A             } +             Else the             { -str =string. Format ("Application Thread error: {0}", e); $             } the             //Write Log the Writelog.writeerrlog (str); theMessageBox.Show ("A fatal error occurred, please contact the author in time! ","System Error", MessageBoxButtons.OK, messageboxicon.error); the         } -         /// <summary> in         ///' Handling UI exceptions the         /// </summary> the         /// <param name= "Sender" ></param> About         /// <param name= "E" ></param> the         Static voidCurrentdomain_unhandledexception (Objectsender, UnhandledExceptionEventArgs e) the         { the             stringstr =""; +Exception error = E.exceptionobject asException; -             stringStrdateinfo ="An unhandled exception occurred with the application:"+ DateTime.Now.ToString () +"\ r \ n"; the             if(Error! =NULL)Bayi             { thestr =string. Format (Strdateinfo +"Application unhandledexception:{0};\n\r Stack information: {1}", error. Message, error. StackTrace); the             } -             Else -             { thestr =string. Format ("Application Unhandlederror:{0}", e); the             } the             //Write Log the Writelog.writeerrlog (str); -MessageBox.Show ("A fatal error occurred, please stop the current operation and contact the author in time! ","System Error", MessageBoxButtons.OK, messageboxicon.error); the         } the  the}

WinForm C # Global Error capture Processing "grooming"

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.