Advertisement
SabirSazzad

Exception handeling

Feb 23rd, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.41 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3.  
  4. using namespace std;
  5. double division(int a, int b)
  6. {
  7.    if( b == 0 )
  8.    {
  9.       throw string("Division by zero condition!");
  10.    }
  11.  
  12.   if(b==2)
  13.     throw 0;
  14.  
  15.    return (a/b);
  16. }
  17.  
  18. int main(){
  19. int a=10, b=3;
  20. try{
  21.     cout<<division(a, b);
  22. } catch(string s){
  23.     cout<<"Error:: "<<s;
  24. }
  25. catch(int flag){
  26.  cout<<"Error_Code:: "<<flag;
  27. }
  28.  
  29.  
  30. cout<<"\n\n";
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement