I want to learn all about exceptions in c++ and I found this code here
to issue some because my OOM killer on Linux is not issuing terminate.
I just don't understand what return d > 1e7 ? throw std::overflow_error("too big") : d;
is doing in particular:
#include <iostream>
#include <stdexcept>
double f(double d)
{
return d > 1e7 ? throw std::overflow_error("too big") : d; //what is going on here?
}
int main()
{
try {
std::cout << f(1e10) << '\n';
} catch (const std::overflow_error& e) {
std::cout << e.what() << '\n'; // information from length_error printed
}
return 0;
}