fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. try {
  6. int a, b;
  7. cout << "Enter two integers: ";
  8. if (!(cin >> a >> b)) throw invalid_argument("Invalid input");
  9. if (b == 0) throw runtime_error("Division by zero");
  10. cout << "Result: " << a / b << endl;
  11. } catch (exception &e) {
  12. cout << "Error: " << e.what() << endl;
  13. }
  14. return 0;
  15. }
  16.  
Success #stdin #stdout 0.01s 5276KB
stdin
 
stdout
Enter two integers: Error: Invalid input