Programming Tips - C2316 (class) cannot be caught as the destructor and/or copy constructor are inaccessible or deleted

Date: 2022dec2 Language: C/C++ Product: MSVC++ Q. C2316 (class) cannot be caught as the destructor and/or copy constructor are inaccessible or deleted A. The fix is to change from a catch by value to catch by reference. For example, I had this issue with CArchiveException Before:
try { ar.WriteString(str); } catch (CArchiveException ex) { // Gets the error :( // do something }
After:
try { ar.WriteString(str); } catch (CArchiveException &ex) { // Compiles fine :) // do something }
More info http://www.google.com/search?q=C2316+site:microsoft.com