What is Exception Handling in C++

Exception handling is the process of responding to the occurrence, during computation of exceptions, anomalous or exceptional conditions requiring special processing often changing the normal flow of program execution. It is provided by specialized programming language constructs or computer hardware mechanisms. We used exception handling when there is a possibility of exception (invalid input ) occurrence. When there is chance that some input disturb the execution of the program then we put that piece of code in exception handling.

Source Code

#include<iostream>
using namespace std;
int main ()
{
   try {
    int num;
    cout<<"Enter Your Number between 1 to 100 : ";
    cin>>num;
    if (num > 0 && num < 100)
    {
     cout<<" \n  Your Number "<<num<<" in Range ";
    }
    else {
     throw num;
    }
   }
    catch ( int exhandler)
   {
     cout<<" \n Your Number is not in Range";
    }
    }

Output of the Program

Exceptional Handling in C++

Share on Google Plus

About Asad

Asad Niazi is Software Engineer , Programmer, Web Developer and a young mentor of BloggersTown and PProgramming. Asad Love to writes about Technology, Programming, Blogging and make money online.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment