adplus-dvertising
frame-decoration

Question

What is the output of this program?
    #include <iostream>
    #include <string>
    using namespace std;
    int main ()
    {
        int num = 3;
        string str_bad = "wrong number used";
        try
        {
            if ( num == 1 )
            {       
                throw 5;
            }
            if ( num == 2 )
            {
                throw 1.1f;
            }
            if ( num != 1 || num != 2 )
            {    
                throw str_bad;
            }
        }
        catch (int a)
        {
            cout << "Exception is: " << a << endl;
        }
        catch (float b)
        {
            cout << "Exception is: " << b << endl;
        }
        catch (...)
        {
            cout  << str_bad << endl;
        }
        return 0;
    }

a.

Exception is 5

b.

Exception is 1.1f

c.

Wrong number used

d.

None of the mentioned

Answer: (c).Wrong number used

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. What is the output of this program?

Similar Questions

Discover Related MCQs

Q. What is the main purpose of the constructor?

Q. Why is it expensive to use objects for exception?

Q. Which alternative can replace the throw statement?

Q. What are the disadvantages if use return keyword to return error codes?

Q. What is most suitable for returning the logical errors in the program?

Q. What is the use of RAII in c++ programing?

Q. How many levels are there in exception safety?

Q. Pick out the correct statement for error handling alternatives.

Q. What will happen when an exception is not processed?

Q. Which header file is used to declare the standard exception?

Q. Where are standard exception classes grouped?

Q. How many types of standard exception are there in c++?

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

Q. What are the perdefined exceptions in c++?

Q. A default catch block catches

Q. Adding a derived class to a base class requires fundamental changes to the base class

Q. If you create an instantiation of a class template with an int, and then create a second instantiation with a double, then

Q. The type to be used in an instantiation of a class template follows ________

Q. When an object-oriented program detects an error within a function, the function _________

Q. When you create a derived class and instantiate an object _____