what is a domain error

后端 未结 7 1433

in c++, has a base class for \'domain errors\', std::domain_error. i don\'t understand under what circumstances i should throw a domain error in my code. all

7条回答
  •  说谎
    说谎 (楼主)
    2021-02-05 19:48

    It's for logic errors of the class of "domain" errors. This could apply to any situation where the input to a function exceeds the allowable domain for it to operate on. That's its stated purpose in the standard.

    For example, you have a function that takes only positive floats, so it throws a domain_error for negative numbers.

提交回复
热议问题