在我的函数里面用 __try{}__except(1){}
出现错误: error C2712: Cannot use __try in functions that require object unwinding__try如何用,msdn上面的例子可以扑获这种异常:char* p = 0;*p = 10;我的程序中正好需要处理这种导致access violation的异常。

解决方案 »

  1.   


    C2712:cannot use __try in functions that require object unwindingWith /GX, a function with structured exception handling cannot have objects that require unwinding (destruction).Possible solutions Move code that requires SEH to another function. 
    Rewrite functions that use SEH to avoid the use of local variables and parameters that have destructors. Do not use SEH in constructors or destructors. 
    Compile using /GX-. 
      

  2.   


    char * p = 0; 
    *p = 10; //  本身这条语句是没有错误的,但在运行时啃定会出错
      

  3.   

    不要在函数体中使用有析构函数的局部变量,可能导致析构函数不会被执行,所以编译器提示出错,尝试把__try块放到另一个更小的函数中。
    比如 CString就有析构函数,但是LPCTSTR就没有