Friday, 7 December 2012

Exception handling cpp program

CPP program for illustrate exception handling

#include<iostream.h>
#include<conio.h>
#include<math.h>
class except
{
          int x;
   public:
          void excheck();
          void give();
};

void except::excheck()
{
          try
          {
                   if(x==1) throw x;
                   else if(x=0) throw ‘x’;
                   else if(x==-1) throw 1.0;

          }
          catch(char c)
                   cout<<”A Character caught\n”;
          catch(float c)
                   cout<<”A Floating point caught\n”;
          catch(int c)
                   cout<<”An Integer caught”;
}
void except::give()
{
          cout<<”Testing Of Catch Try Statements\n\n”;
          cout<<”x = 1\n”;
          excheck();
          cout<<”x = 0\n”;
          excheck();
          cout<<”x = -1\n”;
          excheck();
}
void main()
{
          except e;
          e.give()
          getch();
}

No comments:

Post a Comment