what is a domain error

后端 未结 7 1453

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;
    
        //...
    }
    
    0 讨论(0)
提交回复
热议问题