Home » C++ Programming » Exception Handling » Question
  1. What is the output of this program?
    #include 
    using namespace std;
    void SequenceFun(int StopNumber)
    {
    int N;
    N = 1;
    while (true)
    {
    if (N >= StopNumber)
    throw N;
    cout << N;
    N++;
    }
    }
    int main(void)
    {
    try
    {
    SequenceFun(5);
    }
    catch(int ExNumber)
    {
    cout < cout << "Exception occur with value: " << ExNumber;
    }
    return 0;
    }
    1. Runtime Error
    2. Compilation Error
    3. prints first 4 numbers
    4. prints first 4 numbers and throws exception at 5
    5. None of these
Correct Option: D

In this program, we are printing upto 4 numbers and when executing the 5, we are raising a exception.



Your comments will be displayed only after manual approval.