TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
C++ Coding Standard

Rule:  ERR#012Checked automatically with code checker

Synopsis:Throw only objects of class type
Severity Level:1
Category:Error Handling


Exceptions pass information up the call stack to a point where error handling can be performed. Class types can have member data with information about the cause of the error, and also the class type itself is further documentation of the cause. User exception types should derive from std::exception or one of its derived classes.

Wrong examples:

void m(int x) {
  throw 23; // wrong
  throw x; // wrong
  try {}
  catch (int y) {
    throw; // wrong
    throw y; // wrong

Correct examples:

void m(int x) {
  try {}
  catch (Exception& e) {
    throw; // right
    throw e; // right