This documentation is archived and is not being maintained.

Compiler Error C2316

'exception' : cannot be caught as the destructor and/or copy constructor are inaccessible

An exception was caught by value or by reference but the copy constructor and/or the assignment operator were inaccessible.

This code was accepted by the previous version's compiler but now gives an error. For more information, see Summary of Compile-Time Breaking Changes.

The following sample generates C2316:

// C2316.cpp
// compile with: /EHsc
#include <stdio.h>

extern "C" int printf_s(const char*, ...);

struct B 
    B() {}
    // Delete the following line to resolve.
    // copy constructor
    B(const B&) 

void f(const B&) 

int main() 
        B aB;
    catch (B b) {   // C2316
        printf_s("Caught an exception!\n");