'language/C#'에 해당되는 글 1건

Exceptions

language/C# 2017. 8. 21. 21:28

1. 모든 함수에 try~catch 처리 하지 말자.


2. 모든 thread 진입 함수에서 반드시 try~catch 처리


3. main thread 시작지점에서 unhandled exception 처리


  Application.ThreadException += new ThreadExceptionEventHandler(Application_ThreadException);

  AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);

  Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException);


 //main thread exception

 static void Application_ThreadException(object sender, ThreadExceptionEventArgs e){

   try { ... }

   catch { ... }

   finally reportErrLog(); }

 }


 //other thread exception

 static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e){

   try { ... }

   catch { ... }

   finally 

     reportErrLog(); 

     Application.Exit(); //다른 스레드는 continue할 수 없다. 무조건 종료처리.

   }

 }


블로그 이미지

란마12

,