This documentation is archived and is not being maintained.

Compiler Error C2715

'pointer' : unable to throw or catch an interior __gc pointer or a value type

__value types or __gc pointers are not valid arguments when using exception handling in Managed Extensions for C++. (See Handling Exceptions Using Managed Extensions for C++ for more information.) To resolve this error, use the __box keyword to box the argument.

The following sample generates C2715:

// C2715.cpp
// compile with: /clr
#using <mscorlib.dll>
using namespace System;

__value struct V
{
   int i;
};

void f1()
{
   V v;
   v.i = 10;
   throw v;   // C2715
   // try the following line instead
   // throw __box(v);
}

int main()
{
   try {
      f1();
   }
   catch(V v) {   // C2715
      if ( v.i == 10 ) {
   // try the following lines instead
   // catch(__box V *pv) {
   //   if ( pv->i == 10 ) {
         Console::WriteLine(S"caught 10 - looks OK");
      } else {
         Console::WriteLine(S"catch looks bad");
      }
   }
   catch(...) {
      Console::WriteLine(S"catch looks REALLY bad");
   }
}
Show: