최종 관리되는 예외 처리기에 혼합 native/관리되는 실행?
-
08-06-2019 - |
문제
나는 컴파일된 MFC 응용 프로그램 을 사용하고 나를 구현하기 위해 노력하고 최종 처리기 위해 유엔 그렇지 않으면 붙잡히 관리되는 예외가 있습니다.한 예외는 무시할 CWinApp::ProcessWndProcException
작동합니다.
두 개의 이벤트에 제시된 제프의 CodeProject 문서,Application.ThreadException
고 AppDomain.CurrentDomain.UnhandledException
, 은 발생하지 않습니다.
할 수 있는 사람하는 방법을 제안을 제공해 최종 관리되는 예외 처리기 위해 혼합된 실행?
업데이트:
그것은 나타나는 이러한 예외 처리기만 트리거의 다운스트림 Application.Run
또는 이와 유사한(이 worker 쓰레드 맛을 기억할 수 없는 이름입니다.) 당신이 진정으로 세계적으로 catch 관리되는 예외에 당신을 설치해야 하 SEH 필터입니다.You're not going to get a System.Exception
고하려는 경우 호출 스택을 가을 롤의 워커입니다.
에 MSDN 포럼 질문이 이 주제에 그 제안을 재정의 충분히 낮은 수준의 주요 MFC 스레드에서 try ... catch (Exception^)
.예를 들어, CWinApp::Run
.이 좋은 해결책이 될 수 있습만 보지 않아서 어떤 성능의 안정성에 영향을 줍니다.당신은 할 수있는 기회를 얻은 로그와 함께 호출 스택기 전에 당신은 보석과 피할 수 있습니다 기본 windows unahndled 예외 동작입니다.
해결책
방의 주위에 인터넷,당신이 필요하다는 사실을 확인하여 설치하는 필터를 얻을 관리되지 않는 예외를 통과하는 필터에 그들의 방법을 사용되지 않.서 CLR 및 처리되지 않은 예외가 필터:
CLR 에 의존합 SEH 처리되지 않은 예외의 필터 메커니즘을 잡을 처리하지 않은 예외가 있습니다.
다른 팁
를 사용하여 그 두 가지 예외 처리기 작업해야 합니다.
해야한다"왜?"
이벤트가 발생하지 않을 사용하여 아래:
extern "C" void wWinMainCRTStartup();
// managed entry point
[System::STAThread]
int managedEntry( void )
{
FinalExceptionHandler^ handler = gcnew FinalExceptionHandler();
Application::ThreadException += gcnew System::Threading::ThreadExceptionEventHandler(
handler,
&FinalExceptionHandler::OnThreadException);
AppDomain::CurrentDomain->UnhandledException += gcnew UnhandledExceptionEventHandler(
handler,
&FinalExceptionHandler::OnAppDomainException);
wWinMainCRTStartup();
return 0;
}
// final thread exception handler implementation
void FinalExceptionHandler::OnThreadException( Object^ /* sender */, System::Threading::ThreadExceptionEventArgs^ t )
{
LogWrapper::log->Error( "Unhandled managed thread exception.", t->Exception );
}
// final appdomain exception handler implementation
void FinalExceptionHandler::OnAppDomainException(System::Object ^, UnhandledExceptionEventArgs ^args)
{
LogWrapper::log->Error( "Unhandled managed appdomain exception.", (Exception^)(args->ExceptionObject) );
}
BOOL CMyApp::InitInstance()
{
throw gcnew Exception("test unhandled");
return TRUE;
}
를 사용하여 그 두 가지 예외 처리기 작업해야 합니다.은 당신이 추가되어 있는지 확인 그 곳에서 그들이 될 것이라고와 제대로 설정(즉,응용 프로그램의 리 항목점을 뒀다에서 하나,오른쪽?)