Solution:NIIT/GNIIT Sonugiri0032@gmail.com

Wednesday, January 06, 2016

Exceptional Handling in C++

Exceptional Handling in C++


Structure of the Problem Requirements

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:

0 comments:

GNIITSOLUTION GNIIT SOLUTION. Powered by Blogger.

Translate

Blog Archive

Unordered List