Program to catch specific exceptions

Home Forums C++ Program to catch specific exceptions

This topic contains 0 replies, has 1 voice, and was last updated by  admin 7 months, 4 weeks ago.

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #5238

    admin
    Keymaster

    // Program to catch specific exceptions
    #include <iostream>
    using namespace std;
    void test(int x) throw (int, char, double)
    {
    if(x==0)
    throw x; // int
    else if(x==-1)
    throw ‘x’; // char
    else if(x==1)
    throw 1.0; // double
    }
    int main()
    {
    try
    {
    test(-1);
    test(0);
    test(1);
    }
    catch(…)
    {
    cout<<“caught a character\n”;
    }
    cout<<“End of try catch”;
    return 0;
    }

    • This topic was modified 7 months, 4 weeks ago by  admin.
Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.