Trần Yến Nhi
Member
What will be the output of the following C++ code?
A. 1
B. exception: 2
C.
1
exception: 2
D. exception: 4
Code:
#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;
}
B. exception: 2
C.
1
exception: 2
D. exception: 4