what is a domain error

后端 未结 7 1428

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 20:11

    It refers to mathematical domains.

    float MySqrRoot(float x)
    {
        // sqrt is not valid for negative numbers.
        if (x < 0) throw new domain_error;
    
        //...
    }
    

提交回复
热议问题