<stdexcept>

std::domain_error

class domain_error;
Domain error exception

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 qualify as a domain error.

No component of the standard library throws exceptions of this type. It is designed as a standard exception to be thrown by programs.

1
2
3
4
class domain_error : public logic_error {
public:
  explicit domain_error (const string& what_arg);
};
1
2
3
4
5
class domain_error : public logic_error {
public:
  explicit domain_error (const string& what_arg);
  explicit domain_error (const char* what_arg);
};

成员

构造函数
传递给 what_arg 的字符串与成员 what 返回的值内容相同。

此类从 logic_error 继承了 what 成员函数。

异常安全

强保证: 如果构造函数抛出异常,则没有副作用。

另见