Exception Specifications

1

Which operations don't throw anything?

A. Operations which are reversible.
B. Operations which are irreversible.
C. Operations which are static.
D. Operations which are dynamic.

2

What do you mean by "No exception specification"?

A. It throws nothing
B. It can throw anything
C. It can catch anything
D. none of the mentioned

3

What is the output of this program?

1.
    #include 
2.
    using namespace std;
3.
    int main()
4.
    {
5.
        char* ptr;
6.
        unsigned long int Test = sizeof(size_t(0) / 3);
7.
        cout << Test << endl;
8.
        try
9.
        {
10.
            ptr = new char[size_t(0) / 3];
11.
            delete[ ] ptr;
12.
        }
13.
        catch (bad_alloc &thebadallocation)
14.
        {
15.
            cout << thebadallocation.what() << endl;
16.
        };
17.
        return 0;
18.
    }
A. 4
B. 2
C. bad_alloc
D. depends on compiler

4

What is the output of this program?

1.
    #include 
2.
    #include 
3.
    using namespace std;
4.
    class Myshape
5.
    {
6.
        public:
7.
        virtual void myvirtualfunc() const {}
8.
    };
9.
    class mytriangle: public Myshape
10.
    {
11.
        public:
12.
        virtual void myvirtualfunc() const
13.
        {   
14.
        };
15.
    };
16.
    int main()
17.
    {
18.
        Myshape Myshape_instance;
19.
        Myshape &ref_Myshape = Myshape_instance;
20.
        try 
21.
        {
22.
            mytriangle &ref_mytriangle = dynamic_cast(ref_Myshape);
23.
        }
24.
        catch (bad_cast)
25.
        {
26.
            cout << "Can't do the dynamic_cast lor!!!" << endl;
27.
            cout << "Caught: bad_cast exception. Myshape is not mytriangle.n";
28.
        }
29.
        return 0;
30.
    }
A. Can't do the dynamic_cast lor!!!
B. Caught: bad_cast exception. Myshape is not mytriangle.
C. both a & b
D. none of the mentioned

5

What is the output of this program?

1.
    #include 
2.
    #include 
3.
    #include
4.
    using namespace std;
5.
    int main( )
6.
    {
7.
        try
8.
        {
9.
            string strg1("Test");
10.
            string strg2("ing");
11.
            strg1.append(strg2, 4, 2);
12.
            cout << strg1 << endl;
13.
        }
14.
        catch (exception &e)
15.
        {
16.
            cout << "Caught: " << e.what() << endl;
17.
            cout << "Type: " << typeid(e).name() << endl;
18.
        };
19.
        return 0;
20.
    }
A. out of range
B. bad type_id
C. bad allocation
D. none of the mentioned