Catching Exceptions

1

What should present when throwing a object?

A. constructor
B. copy-constructor
C. destructor
D. none of the mentioned

2

How to handle the exception in constructor?

A. We have to throw an exception
B. We have to return the exception
C. both a & b
D. none of the mentioned

3

What is the output of this program?

1.
    #include
2.
    #include "math.h"
3.
    using namespace std;
4.
    double MySqrt(double d)
5.
    {
6.
        if (d < 0.0)
7.
        throw "Cannot take sqrt of negative number"; 
8.
        return sqrt(d);
9.
    }
10.
    int main()
11.
    {
12.
        double d = 5;
13.
        cout << MySqrt(d) << endl;
14.
    }
A. 5
B. 2.236
C. error
D. Cannot take sqrt of negative number

4

What is the output of this program?

1.
    #include 
2.
    #include 
3.
    using namespace std;
4.
    int main()
5.
    {
6.
        double Op1 = 10, Op2 = 5, Res;
7.
        char Op;
8.
        try 
9.
        {   
10.
            if (Op != '+' && Op != '-' && Op != '*' && Op != '/')
11.
                throw Op;
12.
            switch(Op)
13.
            {
14.
            case '+':
15.
                Res = Op1 + Op2;
16.
                break;
17.
            case '-':
18.
                Res = Op1 - Op2;
19.
                break;
20.
            case '*':
21.
                Res = Op1 * Op2;
22.
                break;
23.
            case '/':
24.
                Res = Op1 / Op2;
25.
                break;
26.
             }
27.
             cout << "n" << Op1 << " " << Op << " "<< Op2 << " = " << Res;
28
         }
29.
         catch (const char n)
30.
         {
31.
             cout << n << " is not a valid operator";
32.
         }
33.
         return 0;
34.
    }
A. 15
B. 5
C. 2
D. is not a valid operator

5

What is the output of this program?

1.
    #include 
2.
    using namespace std;
3.
    double division(int a, int b)
4.
    {
5.
        if ( b == 0 )
6.
        {
7.
            throw "Division by zero condition!";
8.
        }
9.
        return (a / b);
10.
    }
11.
    int main ()
12.
    {
13.
        int x = 50;
14.
        int y = 0;
15.
        double z = 0;
16.
        try 
17.
        {
18.
            z = division(x, y);
19.
            cout << z << endl;
20.
        }
21.
        catch (const char* msg) 
22.
        {
23.
            cout << msg << endl;
24.
        }
25.
        return 0;
26.
    }
A. 50
B. 0
C. Division by zero condition!
D. none of the mentioned