Exceptions That Are Not Errors

1

What kind of exceptions are available in c++?

A. handled
B. unhandled
C. static
D. dynamic

2

How to handle error in the destructor?

A. throwing
B. terminate
C. both a & b
D. none of the mentioned

3

What is the output of this program?

1.
    #include 
2.
    #include 
3.
    using namespace std;
4.
    void myunexpected ()
5.
    {
6.
        cout << "unexpected called\n";
7.
        throw 0;
8.
    }
9.
    void myfunction () throw (int) 
10.
    {
11.
        throw 'x';
12.
    }
13.
    int main () 
14.
    {
15.
        set_unexpected (myunexpected);
16.
        try 
17.
        {
18.
            myfunction();
19.
        }
20.
        catch (int) 
21.
        {
22.
            cout << "caught int\n";
23.
        }
24.
        catch (...)  
25.
        { 
26.
            cout << "caught other exception\n"; 
27.
        }
28.
        return 0;
29.
    }
A. caught other exception
B. caught int
C. unexpected called
D. both b & c

4

What is the output of this program?

1.
    #include 
2.
    using namespace std; 
3.
    int main()
4.
    {
5.
        int x = -1;
6.
        char *ptr;
7.
        ptr = new char[256];
8.
        try 
9.
        {
10.
            if (x < 0)
11.
            {
12.
                throw x;
13.
            }
14.
            if (ptr == NULL)
15.
            {
16.
                throw " ptr is NULL ";
17.
            }
18.
        }
19.
        catch (...) 
20.
        {
21.
            cout << "Exception occurred: exiting "<< 
            endl;
22.
        }
23.
        return 0;
24.
    }
A. -1
B. ptr is NULL
C. Exception occured: exiting
D. none of the mentioned

5

What is the output of this program?

1.
    #include 
2.
    #include 
3.
    using namespace std;
4.
    void myunexpected () 
5.
    {
6.
        cout << "unexpected handler calledn";
7.
        throw;
8.
    }
9.
    void myfunction () throw (int,bad_exception) 
10.
    {
11.
        throw 'x';
12.
    }
13.
    int main (void)
14.
    {
15.
        set_unexpected (myunexpected);
16.
        try 
17.
        {
18.
            myfunction();
19.
        }    
20.
        catch (int) 
21.
        { 
22.
            cout << "caught int\n"; 
23.
        }
24.
        catch (bad_exception be) 
25.
        { 
26.
            cout << "caught bad_exception\n"; 
27.
        }
28.
        catch (...) 
29.
        { 
30.
            cout << "caught other exception \n"; 
31.
        }
32.
        return 0;
33.
    }
A. unexpected handler called
B. caught bad_exception
C. caught other exception
D. both a & b