class
<stdexcept>

std::logic_error

class logic_error;
Logic error exception

This class defines the type of objects thrown as exceptions to report errors in the internal logical of the program, such as violation of logical preconditions or class invariants.

These errors are presumably detectable before the program executes.

It is used as a base class for several logical error exceptions, and is declared as:
1
2
3
4
class logic_error : public exception {
public:
  explicit logic_error (const string& what_arg);
};
1
2
3
4
5
class logic_error : public exception {
public:
  explicit logic_error (const string& what_arg);
  explicit logic_error (const char* what_arg);
};

Its sibling class runtime_error is used as a base for exceptions reporting an error that can only be determined during runtime.

Members

constructor
The string passed as what_arg has the same content as the value returned by member what.

The class inherits the what member function from exception.

Exception safety

Strong guarantee: if the constructor throws an exception, there are no side effects.

See also