Error Handling

1

Which exception is thrown by dynamic_cast?

A. bad_cast
B. bad_typeid
C. bad_exception
D. bad_alloc

2

How do define the user-defined exceptions?

A. inheriting and overriding exception class functionality.
B. overriding class functioality.
C. inheriting class functionality
D. none of the mentioned

3

What is the output of this program?

1.
    #include 
2.
    #include 
3.
    using namespace std;
4.
    struct MyException : public exception
5.
    {
6.
        const char * what () const throw ()
7.
        {
8.
            return "C++ Exception";
9.
        }
10.
    };
11.
    int main()
12.
    {
13.
        try
14.
        {
15.
            throw MyException();
16.
        }
17.
        catch(MyException& e)
18.
        {
19.
            cout << "Exception caught" << std::endl;
20.
            cout << e.what() << std::endl;
21.
        }
22.
        catch(std::exception& e)
23.
        {
24.
        }  
25.
    }
A. C++ Exception
B. Exception caught
C. Exception caught C++ Exception
D. error

4

What is the output of this program?

1.
    #include 
2.
    #include 
3.
    using namespace std;
4.
    int main () 
5.
    {
6.
        try
7.
        {
8.
            int* myarray = new int[1000];
9.
            cout << "allocated";
10.
        }
11.
        catch (exception& e)
12.
        {
13.
            cout << "Standard exception: " << e.what() << endl;
14.
        }
15.
        return 0;
16.
    }
A. allocated
B. Standard exception
C. Depends on the memory
D. error

5

What is the output of this program?

1.
    #include 
2.
    #include 
3.
    using namespace std;
4.
    class myexception: public exception
5.
    {
6.
        virtual const char* what() const throw()
7.
        {
8.
            return "My exception";
9.
        }
10.
    } myex;
11.
    int main () 
12.
    {
13.
        try
14.
        {
15.
            throw myex;
16.
        }
17.
        catch (exception& e)
18.
        {
19.
            cout << e.what() << endl;
20.
        }
21.
        return 0;
22.
    }
A. exception
B. error
C. My exception
D. runtime error