我的一个程序调用了一个第三方的库,该库我是无法修改和调试的。在debug下运行,在调用该库的某个API时偶尔会抛异常,导致程序崩溃。提示框显示:OxC0000005访问0x********地址错误,大致就是这样的信息。
我想捕捉到这个异常,这样进程在运行时就不会崩溃了。可是我用C++的try catch(...)捕获不到,用__try  __except也捕捉不到。
请各位大侠给指点一下,有什么办法能捕捉到这种内存访问错误引起的异常。

解决方案 »

  1.   

    刚刚调用CoInitialize 引起了上述错误更改了一下位置 错误没有关注!
      

  2.   

    http://stackoverflow.com/questions/993551/seh-access-violation-and-stack-guard-pageTo catch access violation exceptions, you need to enable SEH exception handling (C/C++ -> Code Generation -> Enable C++ Exceptions -> Yes, with SEH Exceptions).Be warned though, this will more likely than not make your software less reliable.  You won't always get an access violation on every bad memory access -- it is very possible that your bad pointer points to valid virtual memory.  In that case could overwrite any valid data in your program, but not see the consequences for a long time.You are much better off to ensure that you would never write to bad memory in the first place.
      

  3.   

    用assert试一试,或者debug-》 call back
      

  4.   

    启动时 if (!ProcessShellCommand(cmdInfo))  有时会crash报以上错误。 关注中
      

  5.   

    这个能够捕捉0xC0000005异常
    int SehFilter(DWORD dwExceptionCode)
    {
    switch (dwExceptionCode)
    {
    case EXCEPTION_ACCESS_VIOLATION:
    return EXCEPTION_EXECUTE_HANDLER;
    }
    return EXCEPTION_CONTINUE_SEARCH;
    }int test()
    {
    *(int*)0 = 0;
    return 0;
    }int main(int argc, char* argv[])
    {
    __try
    {
    test();
    printf("test()");
    }
    __except (SehFilter(GetExceptionCode()))
    {
    printf("EXCEPTION_ACCESS_VIOLATION");
    } getch();
    }