Subscribe Us

Responsive Advertisement

Advertisement

Exception Handling Class Type Exeption in cpp

 




#include<bits/stdc++.h>

using namespace std;

class ex

{

    int id;

    string name;

public :

       ex(int x,string name1)

       {

           id=x;

           name=name1;

       }

       void show()

       {

           cout<<name<<" ID "<<id<<" absent\n";

       }

};

void check(int n)

{

    try

    {

        if(n==20)throw ex(n,"OMUK");

        cout<<n<<endl;

    }

    catch(ex e)

    {

        e.show();

    }

}

int main()

{

    check(10);

    check(20);

    check(30);



    return 0;

}


Post a Comment

0 Comments