<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 成員函式。

異常安全

強保證: 如果建構函式丟擲異常,則沒有副作用。

另見