Friday 6 February 2015

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 it Please
asad

About Author!

Asad Niazi is Software Engineer , Programmer, Web Developers and a young mentor of Tech Solutions Desk and Blogging Solutions . Asad Love to writes about Technology, Programming, Blogging and make money online.

0 comments:

Post a Comment