编译器错误 C2725

“exception”:无法根据值或引用引发或捕获托管或 WinRT 对象

托管或 WinRT 异常的类型不正确。

示例

下面的示例生成 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
}

下面的示例生成 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) {}
}