Sunday, February 14, 2016

To Show exception handling.
//Try block throwing exception
#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
    int a;
    int b;
    cout<<"Enter value of A and B"<<endl;
    cin>>a>>b;
    try
    {
        if(b==0)
            throw b;
        else
          cout<<"Result="<<(float)a/b<<endl;
    }
    catch(int i)
    {
        cout<<"Divide by zero exception: B="<<i<<endl;
    }
    cout<<"END"<<endl;
    getch();
    return 0;
}
Output:-
First Execution
Second Execution


0 comments:

Post a Comment

Translate

Sample Text

Powered by Blogger.

Every thing is possible in real world....

Contact us

Name

Email *

Message *

IT Support

Blogroll

You can replace this text by going to "Layout" and then "Page Elements" section. Edit " About "

Video

Our Facebook Page

Popular Posts

Total Pageviews