Exception Handling


  1. Where exception are handled?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    outside the regular code


  1. How many parameters does the throw expression can have?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    In c++ program, We can be able to throw only one error at a time.



  1. What is the output of this program?
    #include <iostream>
    using namespace std;
    void Sequence(int StopN)
    {
    int N;
    N = 3;
    while (true)
    {
    if (N >= StopN)
    throw N;
    cout << N << endl;
    N++;
    }
    }
    int main(void)
    {
    try
    {
    Sequence(4);
    }
    catch(int ExN)
    {
    cout << "exception: " << ExN << endl;
    }
    return 0;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    In this program, We are printing one and raising a exception at 4.


  1. What is the output of this program?
    #include <iostream>
    using namespace std;
    void Example(int num)
    {
    try
    {
    if (num > 0)
    throw num;
    else
    throw 'U';
    }
    catch(int num)
    {
    cout<<"Integer: "<< num << endl;
    }
    catch(char ch)
    {
    cout << "Character: " << ch;
    }
    }
    int main()
    {
    Example(12);
    Example(0);
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    We are passing the integer and character and catching it by using multiple catch statement.



  1. What is the output of this program?
    #include <iostream>
    using namespace std;
    int main()
    {
    int n1 = 20, n2 = 30, n3 = 60;
    float Res;
    try
    {
    if ((n1 - n2) != 0)
    {
    Res = n3 / (n1 - n2);
    cout << Res;
    }
    else
    {
    throw(n1 - n2);
    }
    }
    catch (int k)
    {
    cout<<"Answer is infinite..."<< k;
    }
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    We are manipulating the values, if there is any infinite value means, it will raise an exception.