Witam.
Czy byłby ktoś tak miły i wyjaśnił mi po co jest to "x<0" [nie chodzi mi tutaj o matematykę ;)] po throw skoro po uruchomieniu programu nie wyświetla się żaden komunikat a jedynie ta część z f. termin? Poza tym może mi ktoś wytłumaczyć jak dokładnie działa to exit(7)?
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <exception>
using namespace std;
void termin() {
cout << "termin: exit(7)" << endl;
exit(7);
}
double Sqrt(double x) {
if (x < 0) throw "x < 0";
return sqrt(x);
}
int main() {
set_terminate(&termin);
double z, x;
x = -16;
z = Sqrt(x);
cout << "Sqrt(" << x << ")=" << z << endl;
}
Dzięki!!!