Grouping of Exceptions

1

When exceptions are used?

A. To preserve the program
B. Exceptions are used when postconditions of a function cannot be satisfied.
C. Exceptions are used when postconditions of a function can be satisfied.
D. none of the mentioned

2

Pick out the correct Answer.

A. Exceptions are not suitable for critical points in code.
B. Exception are suitable for critical points in code.
C. Both a & b
D. none of the mentioned

3

What is the output of this program?

1.
    #include 
2.
    using namespace std;
3.
    void PrintSequence(int StopNum)
4.
    {
5.
        int Num;
6.
        Num = 1;
7.
        while (true)
8.
        {
9.
            if (Num >= StopNum)
10.
                throw Num;
11.
            cout << Num << endl;
12.
            Num++;
13.
        }
14.
    }
15.
    int main(void)
16.
    {
17.
        try
18.
        {
19.
            PrintSequence(2);
20.
        }
21.
        catch(int ExNum)
22.
        {
23.
            cout << "exception: " << ExNum << endl;
24.
        }
25.
        return 0;
26.
    }

a) 1

b) exception: 2

c) 1

exception: 2

d) none of the mentioned


4

What is the output of this program?

1.
    #include 
2.
    using namespace std;
3.
    void test(int x)
4.
    {
5.
        try
6.
        {
7.
            if (x > 0)
8.
                throw x;
9.
            else
10.
                throw 'x';
11.
        }
12.
        catch(int x)
13.
        {
14.
            cout<<"integer:"< 
                                                    
A. integer:10character:x
B. integer:10
C. character:x
D. none of the mentioned

5

What is the output of this program?

1.
    #include 
2.
    using namespace std;
3.
    int main()
4.
    {
5.
        int a = 10, b = 20, c = 30;
6.
        float  d;
7.
        try
8.
        {
9.
            if ((a - b) != 0)
10.
            {
11.
                d = c / (a - b);
12.
                cout << d;
13.
            }
14.
            else
15.
            {
16.
                throw(a - b);
17.
            }
18.
        }
19.
        catch (int i)
20.
        {
21.
            cout<<"Answer is infinite "< 
                                                    
A. 10
B. -3
C. 15
D. none of the mentioned