Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일
 
(연관된 글이 2개 있습니다.)

Windows Form의 Load 이벤트에서 발생하는 예외가 Visual Studio에서 잡히지 않는 문제

마침 질문해 주신 분이 계셔서. ^^

VS2010의 윈폼의 Load 이벤트에서 예외가 잡혀지지 않습니다.
; https://www.sysnet.pe.kr/3/0/990

사실, 제 경우에도 여러 번 겪은 상황이었는데 지금까지 별다른 의문을 갖어본 적이 없습니다. 그냥 ^^; Load 이벤트에서만 그런 식으로 밖에 처리가 안되나 보다... 했었습니다.

검색을 해보니, 역시 마이크로스프트 측에서도 bug라고 인정하는 글이 나옵니다.

VS do not stop execution on error
; http://social.msdn.microsoft.com/Forums/en-US/vsdebug/thread/27f247e0-b856-45f5-aae7-fb5d96b3bc0f/

그리고, 우회적인 해결책이라면 "I suggest you to switch to x86 system for development."라고 말한 것처럼 x86 윈도우 환경으로 바꾸는 정도입니다. (제 테스트 PC의 x86 환경에서는 실제로 Load 이벤트에서 정상적으로 예외가 잡혔습니다.)




제 경우에 이런 때 어떻게 대응하냐고 물으셨는데요. 개인적으로 2가지 방법을 씁니다.

간단하게는, 코드 상에서 다음과 같이 Load 이벤트의 처음과 끝을 감싸는 try/catch를 만들고 catch에 BP(Breakpoint)를 걸어둡니다.

ex_in_load_event_1.png

그러면, 어떤 예외가 발생했는지와 콜 스택까지 모두 확인할 수 있어서 코드 라인까지 확인할 수 있습니다.

그 외에, 코드를 바꾸지 않는 방법도 있지만 더 복잡합니다. 우선, 디버거로 실행한 후 "Output" 창에 출력된 메시지를 확인합니다. 예를 들어, 위의 코드에서는 다음과 같은 예외가 남아 있습니다.

ex_in_load_event_2.png

'WindowsFormsApplication1.vshost.exe' (Managed (v4.0.30319)): Loaded 'D:\Settings\desktop\load_evt\WindowsFormsApplication1\WindowsFormsApplication1\bin\Debug\WindowsFormsApplication1.exe', Symbols loaded.
A first chance exception of type 'System.ApplicationException' occurred in WindowsFormsApplication1.exe


이렇게 알아낸 "System.ApplicationException"을 다음의 글에 설명한 데로 "Debug" / "Exceptions..." 메뉴(Ctrl+D,E)로 들어가서 "Thrown" 항목에 체크를 해 둡니다.

First-Chance Exception
; https://www.sysnet.pe.kr/2/0/510

이렇게 한 다음, 다시 "F5 디버깅"을 시작하면 Load 이벤트 안에서도 정확하게 그 위치에서 예외가 잡힙니다.




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]

[연관 글]






[최초 등록일: ]
[최종 수정일: 6/21/2021]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... 61  62  63  64  65  66  67  68  69  [70]  71  72  73  74  75  ...
NoWriterDateCnt.TitleFile(s)
11895정성태5/12/201913739.NET Framework: 832. ML.NET Model Builder - 회귀(Regression), 다중 분류(Multi-class classification) 예제파일 다운로드1
11894정성태5/10/201914882VS.NET IDE: 135. Visual Studio - ML.NET Model Builder 소개 [5]
11893정성태5/10/201912500오류 유형: 535. C# 6.0 이상의 문법을 컴파일 시 오류가 발생한다면?
11892정성태5/10/201912544웹: 38. HTTP Cookie의 expires 시간 형식(RFC7231)
11891정성태5/9/201915022.NET Framework: 831. (번역글) .NET Internals Cookbook Part 12 - Memory structure, attributes, handles
11890정성태5/8/201910781개발 환경 구성: 439. "Visual Studio Enterprise is required to execute the test." 메시지와 관련된 코드 기록
11889정성태5/8/201911638개발 환경 구성: 438. mstest, QTAgent의 로그 파일 설정 방법
11888정성태5/8/201926869.NET Framework: 830. C# - 비동기 호출을 취소하는 CancellationToken의 간단한 예제 코드 [1]파일 다운로드1
11887정성태5/8/201913362.NET Framework: 829. C# - yield 문을 사용할 수 있는 메서드의 조건
11886정성태5/7/201912432오류 유형: 534. mstest.exe 실행 시 "Visual Studio Enterprise is required to execute the test." 오류 [2]
11885정성태5/7/20199396오류 유형: 533. mstest.exe 실행 시 "File extension specified '.loadtest' is not a valid test extension." 오류 발생
11884정성태5/5/201913073.NET Framework: 828. C# DLL에서 Win32 C/C++처럼 dllexport 함수를 제공하는 방법 - 두 번째 이야기
11883정성태5/3/201917389.NET Framework: 827. C# - 인터넷 시간 서버로부터 받은 시간을 윈도우에 적용하는 방법파일 다운로드1
11882정성태5/2/201914299.NET Framework: 826. (번역글) .NET Internals Cookbook Part 11 - Various C# riddles파일 다운로드1
11881정성태4/28/201914543오류 유형: 532. .NET Core 프로젝트로 마이그레이션 시 "CS0579 Duplicate 'System.Reflection.AssemblyCompanyAttribute' attribute" 오류 발생
11880정성태4/25/201911233오류 유형: 531. 이벤트 로그 오류 - Task Scheduling Error: m->NextScheduledSPRetry 1547, m->NextScheduledEvent 1547
11879정성태4/24/201916463.NET Framework: 825. (번역글) .NET Internals Cookbook Part 10 - Threads, Tasks, asynchronous code and others파일 다운로드2
11878정성태4/22/201914471.NET Framework: 824. (번역글) .NET Internals Cookbook Part 9 - Finalizers, queues, card tables and other GC stuff파일 다운로드1
11877정성태4/22/201914428.NET Framework: 823. (번역글) .NET Internals Cookbook Part 8 - C# gotchas파일 다운로드1
11876정성태4/21/201914258.NET Framework: 822. (번역글) .NET Internals Cookbook Part 7 - Word tearing, locking and others파일 다운로드1
11875정성태4/21/201914624오류 유형: 530. Visual Studo에서 .NET Core 프로젝트를 열 때 "One or more errors occurred." 오류 발생
11874정성태4/20/201914631.NET Framework: 821. (번역글) .NET Internals Cookbook Part 6 - Object internals파일 다운로드1
11873정성태4/19/201913590.NET Framework: 820. (번역글) .NET Internals Cookbook Part 5 - Methods, parameters, modifiers파일 다운로드1
11872정성태4/17/201914054.NET Framework: 819. (번역글) .NET Internals Cookbook Part 4 - Type members파일 다운로드1
11871정성태4/16/201913909.NET Framework: 818. (번역글) .NET Internals Cookbook Part 3 - Initialization tricks [3]파일 다운로드1
11870정성태4/16/201911587.NET Framework: 817. Process.Start로 실행한 콘솔 프로그램의 출력 결과를 얻는 방법파일 다운로드1
... 61  62  63  64  65  66  67  68  69  [70]  71  72  73  74  75  ...