Search This Blog

Sunday 1 May 2016

Write a simple Program for Exception Handling with Multiple Catch blocks and also generic handler.

 Practical - 39


#include<iostream>
using namespace std;

void add(int x)
{
    try{
    if(x==0)
    {
        throw 'x';
    }
    else{
        if(x==1)
        throw x;
    else
        throw 5.0;
    }}
    catch(char c)
    {
        cout<<"\nChar exception";
    }
    catch(int i)
    {
        cout<<"\nint exception";
    }
    catch(double z)
    {
        cout<<"\ndouble exception";
    }
    /*
    remove all catch above and un comment this
    catch(...)
    {
        cout<<"\nFound exception generic:";
    }
    */
}

int main()
{
        add(0);
        add(1);
        add(5.5);
    return 0;
}

No comments:

Post a Comment