Home » C++ Programming » Exception Handling » Question
  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. 3
      exception: 4
    2. exception: 4
    3. 3
    4. exception: 4
      3
    5. None of these
Correct Option: A

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



Your comments will be displayed only after manual approval.