본문 바로가기
Programming/.net

[.net] C# 예외 발생 시 윈폼 메시지 박스에 띄울 내용 정리

by x-coder 2023. 9. 15.

Hello. { #Somebody }

C# 프로그램 예외 발생 시 Winform Message Box에 넣을 내용

 

물론 훌륭한 프로그래머들은 더 좋은 방법을 알고 있겠지만,아래와 같이 메시지 포맷을 정형화 해서 사용하면 좀 더 쉽게 쓸 수 있지 않을까 해서 기록합니다.

 

 

// 전역벽수 선언

private string mainErrorMsgFormat;
private string mainErrorMsg;


...
...


// 생성자 혹은 Initialize 메서드에 선언
mainErrorMsgFormat = "Class : {0}\nFunction Name : {1}\nError Type : {2}\nError Message : {3}";


...
...


// 각 Class / Method에 사용
try
{
	// source
}
catch(Exception ex)
{
	mainErrorMsg = string.Format(mainErrorMsgFormat, 
    				this.GetType().FullName, 
                                MethodInfo.GetCurrentMethod().Name, 
                                ex.GetType().FullName, 
                                ex.Message);
    MessageBox.Show(mainErrorMsg);
}
Winform MessageBox에 Class 명칭, Function 명칭, Exception 명칭, 에러 메시지를 보여줄 수 있다.

 

 

Keep In Short and Simple

Bye. { #Somebody }

'Programming > .net' 카테고리의 다른 글

[.net] C# Stopwatch 사용 방법 (로직 수행 시간 측정)  (0) 2023.09.15