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

,

"파일경로" 파일을 "xxx.exe"(으)로 복사할 수 없습니다. 'xxx.exe' 파일은 다른 프로세스에서 사용 중이므로 프로세스에서 액세스할 수 없습니다. 


VS 버그인듯...


빌드전 이벤트에 추가


if exist "$(TargetPath).locked" del "$(TargetPath).locked"

if exist "$(TargetPath)" if not exist "$(TargetPath).locked" move "$(TargetPath)" "$(TargetPath).locked"

if exist "$(TargetDir)$(TargetName).pdb.locked" del "$(TargetDir)$(TargetName).pdb.locked"

if exist "$(TargetDir)$(TargetName).pdb" if not exist "$(TargetDir)$(TargetName).pdb.locked" move "$(TargetDir)$(TargetName).pdb" "$(TargetDir)$(TargetName).pdb.locked"

블로그 이미지

란마12

,

EventLog el = new EventLog("Application");

el.Source = "my_src_name";

el.WriteEntry("오류 메시지", EventLogEntryType.Error);


다음과 같은 오류 발생

Security Exception

 Description: The application attempted to perform an operation not allowed by the security policy.  To grant this application the required permission please contact your system administrator or change the application's trust level in the configuration file.

Exception Details: System.Security.SecurityException: The source was not found, but some or all event logs could not be searched.  Inaccessible logs: Security.

Source Error:

[No relevant source lines]


Source File: c:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\license\3ebadbd0\51884812\App_Web_2wv6qvf1.0.cs    Line: 0

Stack Trace:

[SecurityException: The source was not found, but some or all event logs could not be searched.  Inaccessible logs: Security.]
....


해결방법

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EventLog -> NETWORK SERVICE user에 Full Control 퍼미션 추가

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\EventLog\Application\my_src_name 키 직접 추가

블로그 이미지

란마12

,