Exception handling in C++

Exception handling

Source code :

#include<iostream>

using namespace std;

int main(){
    
    int a = 10 ,b = 10,c = 20;
    float  d;
   
    try{
      
        if((a-b)!=0){
              
            d=c/(a-b);
            cout<<"Result is : "<<d;
             
        }else{
              
            throw(a-b);
        }
        
    }catch(int i){
        
        cout<<"Infinte values can't be printed because a-b is:"<<i;
   }
   
}

Output :

Infinte values can't be printed because a-b is:0

Output :


                

Comments :