RosettaCodeData/Task/Exceptions-Catch-an-exception-thrown-in-a-nested-call/C++/exceptions-catch-an-exception-thrown-in-a-nested-call.cpp
Ingy döt Net 764da6cbbb CDE
2013-04-10 16:57:12 -07:00

28 lines
392 B
C++

#include <iostream>
class U0 {};
class U1 {};
void baz(int i)
{
if (!i) throw U0();
else throw U1();
}
void bar(int i) { baz(i); }
void foo()
{
for (int i = 0; i < 2; i++)
{
try {
bar(i);
} catch(U0 e) {
std::cout<< "Exception U0 caught\n";
}
}
}
int main() {
foo();
std::cout<< "Should never get here!\n";
return 0;
}