O
Old Wolf
In the following code:
1) Is the exception allowed to be thrown even if the
user never enters '1'?
2) If the user enters '1' a second time, what happens?
How does the compiler typically implement all this?
#include <iostream>
int x = 0;
struct S
{
void foo() { std::cout << "In foo" << std::endl; }
S() { if (x++ == 0) throw 1; }
};
int main()
{
while (1) switch( std::cin.get() )
{
case '1': try { static S s; s.foo(); } catch(...) {} break;
case EOF: return 0;
}
}
1) Is the exception allowed to be thrown even if the
user never enters '1'?
2) If the user enters '1' a second time, what happens?
How does the compiler typically implement all this?
#include <iostream>
int x = 0;
struct S
{
void foo() { std::cout << "In foo" << std::endl; }
S() { if (x++ == 0) throw 1; }
};
int main()
{
while (1) switch( std::cin.get() )
{
case '1': try { static S s; s.foo(); } catch(...) {} break;
case EOF: return 0;
}
}