catch Access Violation 코드

Access Violation 을 잡으려면 빌게 SEH 밖에 방법이 없나보다.
catch (...) 로 잡을 수 있을 줄 알았는데 디버그 모드에서만 되네..

기본 런타임 검사 옵션 /RTC1, /RTCsu 이 영향을 미치는데..
최적화 옵션하고 같이 쓸 수 없다 음...

근데 이거 개체 해제 기능 쓰는 함수라고 같이 못 쓰는데 골아프네;;
C++에서 RAII 기법을 못 쓰면 어떻게 사냐;-_-

#include <iostream>
#include <windows.h>

int main()
{
    __try {
        char *p = (char *)11000;
        *p = 3333;
    }
    __except(EXCEPTION_EXECUTE_HANDLER)
    {
        std::cout << "AV as expected." << std::endl;
    }
   
    return 0;
}


추가.
아! /EHa 옵션으로 컴파일하면 된다..!
Use /EHa to specify the asynchronous exception handling model (C++ exception handling with structured exception handling exceptions). /EHa may result in a less performant image because the compiler will not optimize a catch block as aggressively, even if the compiler does not see a throw.

Use /EHa if you want to catch an exception raised with something other than a throw.

트랙백

이 글과 관련된 글 쓰기 (트랙백 보내기)
TrackbackURL : http://www.xeraph.com/tb/2034674 [도움말]

덧글

댓글 입력 영역