Monday, June 3, 2019

Exception Handling/Error handling


          Exception Handling/Error handling

Type of error :
      1.   Syntax error
      2.   Logical error
      3.   Run time error  -----> Exception handling
By the use of exception handling,
We can handle the run time error.

For handling the exception:
      1.   try              2. catch              3.throw


#include<iosream.h>
#include<conio.h>
void main()
{
          try
          {
                   int n,m;
                   cin>>n>>m;
                   int y=n/m;
                   cout<<”thanks”;
          }
          catch(exception e)
          {
                   cout<<”please check variable – should not be 0”<<e;
          }
          try
{
          trow 20;
          }
          catch(int n)
          {
                   cout<<n;
          }
          getch();
}

[Note: to perform exception handling use “visual c” s/w …..]

No comments:

Post a Comment