I have written a simple test c++ program (below) that takes the square root of a negative number and then tries to print it out. I would like to trap the floating point exception caused by taking the square root of a negative number (e.g., I'd like the program to halt with an error after the floating point exception). On Intel Macs, I know how to do this. Is this possible on an Apple Silicon Mac?
#include <cmath>
#include <iostream>
int main() {
const double x = -1.0;
double y = x;
y = sqrt(y); // floating point exception...possible to build program so it terminates here?
std::cout << y << "\n";
return 0;
}
Selecting any option will automatically load the page