Skip to content

Instantly share code, notes, and snippets.

@vineethm1627
Created March 2, 2021 06:26
Show Gist options
  • Save vineethm1627/21f7b19c22f63d435093ef2840345129 to your computer and use it in GitHub Desktop.
Save vineethm1627/21f7b19c22f63d435093ef2840345129 to your computer and use it in GitHub Desktop.
#include <iostream>
using namespace std;
int main() {
try {
double num1;
cout <<"Enter the first number:";
cin >> num1;
double num2;
cout <<"Enter the second number:";
cin >> num2;
if(num2 == 0.0) {
throw 0.0;
}
cout <<"Result:"<<num1 / num2;
}
catch(...) {
cout <<"You cannot divide any number by zero! Because in ordinary arithmetic, the expression has no meaning, as there is no number which, when multiplied by 0, gives a (assuming a ≠ 0), and so division by zero is undefined.";
}
return 0;
}
@vineethm1627
Copy link
Author

To catch exception of any type:

try {
  // code
} catch(...) {
  // code to handle exceptions
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment