adplus-dvertising
frame-decoration

Question

What is the output of this program?
    #include <iostream>
    using namespace std;
    void PrintSequence(int StopNum)
    {
        int Num;
        Num = 1;
        while (true)
        {
            if (Num >= StopNum)
                throw Num;
            cout << Num << endl;
            Num++;
        }
    }
    int main(void)
    {
        try
        {
            PrintSequence(2);
        }
        catch(int ExNum)
        {
            cout << "exception: " << ExNum << endl;
        }
        return 0;
    }

a.

1

b.

exception: 2

c.

1 exception: 2

d.

none of the mentioned

Answer: (c).1 exception: 2

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. What is the output of this program?