Using exception | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Using exception

Code to handle exceptions in c++

10th Dec 2016, 12:24 PM
Edison
1 Answer
0
// Validando entradas // EdiJim // Thanks for you like... #include <iostream> using namespace std; int main() { try { double num1; double num2; cin >> num1; cin >> num2; cout <<"Su dividendo: "<<num1<<endl; cout <<"Su divisor: "<<num2<<endl; if(num2 == 0) { throw 0; } if (num2 == 1)throw 1; cout <<"Resultado: "<<num1 / num2; } catch(int x) { if (x==0)cout <<"Division por cero no permitida!"; if (x==1)cout <<"Estas dividiendo por uno"; } }
10th Dec 2016, 12:27 PM
Edison