Standard Exceptions

1

What are the perdefined exceptions in c++?

A. Memory allocation errors
B. I/O errors
C. both a & b
D. None of the mentioned

2

Which of the following is best to include under try block?

A. static values
B. const values
C. dynamic allocations
D. none of the mentioned

3

What is the output of this program?

1.
    #include 
2.
    #include 
3.
    using namespace std;
4.
    class Test
5.
    {
6.
        public:
7.
        Test();
8.
        virtual ~Test();
9.
    };
10.
    int main()
11.
    {
12.
        Test *ptrvar = NULL;
13.
        try 
14.
        {
15.
            cout << typeid(*ptrvar).name() << endl;
16.
        }
17.
        catch (bad_typeid) 
18.
        {
19.
            cout << "The object is null" << endl;
20.
        }
21.
        return 0;
22.
    }
A. No exception arises
B. The object is null
C. Error
D. None of the mentioned

4

What is the output of this program?

1.
    #include 
2.
    #include 
3.
    using namespace std;
4.
    class shape
5.
    {
6.
        public:
7.
        virtual void myvirtualfunc() const {}
8.
    };
9.
    class mytriangle: public shape
10.
    {
11.
        public:
12.
        virtual void myvirtualfunc() const
13.
        {   
14.
        };
15.
    };
16.
    int main()
17.
    {
18.
        shape shape_instance;
19.
        shape &ref_shape = shape_instance;
20.
        try 
21.
        {
22.
            mytriangle &ref_mytriangle = dynamic_cast(ref_shape);
23.
        }
24.
        catch (bad_cast) 
25.
        {
26.
            cout << "Caught: bad_cast exception\n";
27.
        }
28.
        return 0;
29.
    }
A. Caught standard exception
B. No exception arises
C. Caught: bad_cast exception
D. None of the mentioned

5

What is the output of this program?

 
1.
    #include 
2.
    using namespace std;
3.
    int main()
4.
    {
5.
        char* ptr;
6.
        unsigned long int a = (size_t(0) / 3);
7.
        cout << a << 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. 0
B. 2
C. bad_alloc
D. depends on compiler