Exception Handling


  1. What is the output of this program?
    #include <iostream>
    #include <exception>
    using namespace std;
    class ExceptionExample: public exception
    {
    virtual const char* what() const throw()
    {
    return "Exception Occurred...";
    }
    } NewExcep;
    int main ()
    {
    try
    {
    throw NewExcep;
    }
    catch (exception& excep)
    {
    cout << excep.what() << endl;
    }
    return 0;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    In this program, We are arising a standard exception and catching that and returning a statement.


  1. Which is used to check the error in the block?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    The try block is used to check for errors, if there is any error means, it can throw it to catch block.



  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.