Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) std::domain_error

 

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

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict