Code for handling exceptions in C++
#include <iostream>using namespace std;double division(int a, int b){ if( b == 0 ) { throw "Division by zero condition!"; } return (a/b);}int main (){int x,y;double z;cout<<"Enter value of x and yn";cin>>x>>y; try { z = division(x, y); cout << z<<"n"; }catch (const char* msg){ cout << msg << endl; } return 0;}
Comments
Post a Comment