Compiler Error C2743

 

For the latest documentation on Visual Studio 2017 RC, see Visual Studio 2017 RC Documentation.

'type' : cannot catch a native type with __clrcall destructor or copy constructor

A module compiled with /clr (not /clr:pure) attempted to catch an exception of native type and where the type's destructor or copy constructor uses __clrcall calling convention.

When compiled with /clr (not /clr:pure), exception handling expects the member functions in a native type to be __cdecl and not __clrcall. Native types with member functions using __clrcall calling convention cannot be caught in a module compiled with /clr.

For more information, see /clr (Common Language Runtime Compilation).

The following sample generates C2743.

// C2743.cpp  
// compile with: /clr  
public struct S {  
   __clrcall ~S() {}  
};  
  
public struct T {  
   ~T() {}  
};  
  
int main() {  
   try {}  
   catch(S) {}   // C2743  
   // try the following line instead  
   // catch(T) {}  
  
   try {}  
   catch(S*) {}   // OK  
}  

Show: