Exception Handling


  1. What is the output of this program?
    #include <iostream>
    #include <typeinfo>
    using namespace std;
    class N
    {
    };
    int main()
    {
    char ch; float n;
    if (typeid(ch) != typeid(n))
    cout << typeid(ch).name() << endl;
    cout << typeid(N).name();
    return 0;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    We are checking the type id of char and float as they are not equal, We are printing c and 1N.


  1. What is the output of this program?
    #include <iostream>
    using namespace std;
    void DivFunction(const double num1, const double num2);
    int main()
    {
    double option1=20, option2=5;
    try
    {
    DivFunction(option1, option2);
    }
    catch (const char* S)
    {
    cout << "Bad Operator caught: " << S;
    }
    return 0;
    }
    void DivFunction(const double num1, const double num2)
    {
    double Res;
    if (num2 == 0)
    throw "Division by zero not allowed";
    Res = num1 / num2;
    cout << Res;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: E

    We are dividing 20 and 5 in this program and we are using the throw statement in the function block.



  1. What operation can be performed by destructor?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    It will be used to free all the resources that are used by the block of code during execution.


  1. What is the use of RAII in c++ programming?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    Improve the exception safety



  1. How many levels are there in exception safety?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    The three levels of exception safety are basic, strong and no throw.