Exception Handling | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Exception Handling

#include <iostream> using namespace std; int main() { try { int num1; cout <<"Enter the first number:"; cin >> num1; int num2; cout <<"Enter the second number:"; cin >> num2; if(num2 == 0) { throw 0; } cout <<"Result:"<<num1 / num2; } catch(int x) { cout <<"Division by zero!"; } } i want to division's output

25th Oct 2017, 3:33 PM
Shivani Goyal
1 Answer
+ 4
The cout should be in the try{}
25th Oct 2017, 3:44 PM
👑 Prometheus 🇸🇬
👑 Prometheus 🇸🇬 - avatar