Expand Minimize
0 out of 1 rated this helpful - Rate this topic

Compiler Error C2725

'exception' : unable to throw or catch a managed object by value or reference

The type of a managed exception was not correct.

The following sample generates C2725.

// C2725.cpp
// compile with: /clr
ref class R {
public:
   int i;
};

int main() {
   R % r1 = *gcnew R;
   throw r1;   // C2725

   R ^ r2 = gcnew R;
   throw r2;   // OK   
}

The following sample generates C2725.

// C2725b.cpp
// compile with: /clr
using namespace System;
int main() {
   try {}
   catch( System::Exception%) {}   // C2725
   // try the following line instead
   // catch( System::Exception ^e) {}
}

The following sample generates C2725.

// C2725c.cpp
// compile with: /clr:oldSyntax
using namespace System;
int main() {
   try {}
   catch( System::Exception&) {}   // C2725
   // try the following line instead
   // catch( System::Exception *e) {}
}
Did you find this helpful?
(1500 characters remaining)

Community Additions

ADD
© 2013 Microsoft. All rights reserved.