Posts

Showing posts from July, 2024

TRY AND CATCH BLOCK WITH THE NUMBER

 #include<iostream> using namespace std; int main() {     int a,b; cout<<"enter two numbers"<<"\n"; cin>>a; cin>>b; try {     if(b==0 or b==2)         throw 0;     cout<<a/b<<"\n";     cout<<"success"; } catch(int i) {     cout<<"error occured"<<i; } }

TRY AND CATCH BLOCK WITH THE STRING

 #include<iostream> using namespace std; int main() {     int a,b;  cout<<"enter two number"<<"\n";  cin>>a;  cin>>b;  try  {      if(b==0)         throw "DIVISION BY ZERO ERROR";  cout<<"result "<<a/b<<"\n";   cout<<"SUCCESS";  }  catch(const char *ch) {     cout<<"error ocuured "<<ch; } }