Skip to content

Latest commit

 

History

History
68 lines (40 loc) · 1.85 KB

File metadata and controls

68 lines (40 loc) · 1.85 KB

 

 

 

 

 

 

std::domain_error is an exception thrown when a mathematically invalid domain is used.

 

std::domain_error is a derived class from std::logic_error. std::logic_error is a derived class from td::exception.

 


#include <cmath> #include <iostream> #include <stdexcept> int main() {   try   {     const double x = std::acos(2.0);     std::cout << x << '\n';   }   catch (std::domain_error& e)   {     std::cout << e.what() << '\n';   }   catch (...)   {     std::cout << "Something unexpected happened" << '\n';   } }

 

Note: I hoped that std::domain_error would be thrown, instead the value 'nan' would be written to the screen.

 

 

 

 

 

External links