Export (0) Print
Expand All
Expand Minimize
4 out of 19 rated this helpful - Rate this topic

Compiler Error C2712

Error Message

cannot use __try in functions that require object unwinding

With /EHsc, 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 without /EHsc.

Example

C2712 can occur if you compile with /clr:pure and declare a static array of pointers-to-functions in a __try block. A static member requires the compiler to use dynamic initialization under /clr:pure, which implies C++ exception handling. However, C++ exception handling is not allowed in a __try block.

The following sample generates C2712.

// C2712.cpp
// compile with: /clr:pure /c
struct S1 {
   static int smf();
   void fnc();
};

void S1::fnc() {
   __try {
      static int (*array_1[])() = {smf,};   // C2712

      // OK
      static int (*array_2[2])();
      array_2[0] = smf;
    }
    __except(0) {}
}
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.