- 1

Why this is not working.

#include<iostream> using namespace std; int main() { int n1,n2; cout<<"Enter first Number :"; cin>>n1; cout<<"Enter second Number :"; cin>>n2; if(n2==0){ throw 0; } cout<<"Division is :"<<n1/n2; catch (int x){ cout<<"Can't divide by zero" <<x; } return 0; }

19th Nov 2021, 9:22 AM
Vikalp Monas
Vikalp Monas - avatar
3 Respostas
+ 5
wrap your if condition inside the try block.
19th Nov 2021, 9:28 AM
zexu knub
zexu knub - avatar
+ 4
Vikalp Monas Learn 80.1 lesson again because that's not a proper syntax of try catch.
19th Nov 2021, 10:38 AM
A͢J
A͢J - avatar
+ 1
Please always tag the language you're asking about. https://code.sololearn.com/W3uiji9X28C1/?ref=app
19th Nov 2021, 6:11 PM
Simon Sauter
Simon Sauter - avatar