Wednesday, November 2, 2022

Try and catch

 # include<iostream>

using namespace std;


int main()

{

int x,y,z;

cout<<"enter x:";

cin>>x;

cout<<"enter y:";

cin>>y;

cout<<"enter z:";

cin>>z;

try

{

if(y==0)

throw 1;

z=x/y;

cout<<z<<endl;

}

catch(int e)

{

cout<<"division by zero :"<<e<<endl;

}

cout<<"bye"<<endl;

}

No comments:

Post a Comment

CONSTRUCTURE IN PARENT CLASS

class Parent {     public Parent()     {         System.out.println("Parent Constrcutor");     }              } class Child extend...