#include #include #include using namespace std; class Error { }; class InvalidArgument : public Error { }; class OutOfMemory : public Error { }; class IOError : public Error { }; double f4(double d) { if(d >= 0) { return sqrt(d); } else { throw InvalidArgument(); } } int f3(int i, int n) { if(n > 100) { throw OutOfMemory(); } double *d = new double[n]; double result = 0; try { for(int k=0; k> i; int result = f2(i); cout << "Il risultato è: " << result << endl; break; } catch(InvalidArgument) { cout << "Errore! il valore che hai inserito è negativo. Riprova." << endl; } catch(OutOfMemory) { cout << "Errore! il valore che hai inserito è troppo grande. Riprova." << endl; } catch(Error) { cout << "Errore! il valore che hai inserito non è accettabile. Riprova." << endl; } catch(...) { cout << "Errore!" << endl; } } } int main() { try { f1(); } catch(InvalidArgument) { cout << "Errore" << endl; } cout << "Fine del programma" << endl; }