class

std::domain_error

<stdexcept>
class domain_error;
Domain error exception
domain_error

This class defines the type of objects thrown as exceptions to report domain errors.

Generally, the domain of a mathematical function is the subset of values that it is defined for. For example, the square root function is only defined for non-negative numbers. Thus, a negative number for such a function would be a domain error.

This class is designed so that any program, not just the elements of the standard library, can throw it as an exception.

It is defined as:
1
2
3
4
class domain_error : public logic_error {
public:
  explicit domain_error (const string& what_arg);
};


Members

constructor
The constructor takes a standard string object as parameter. This value is stored in the object, and its value is used to generate the C-string returned by its inherited member what.

The class inherits the what member function from exception, along with its copy constructor and assignment operator member functions.

See also