mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-01-29 13:32:33 +00:00
065c0b95a3
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8158 91177308-0d34-0410-b5e6-96231b3b80d8
41 lines
717 B
C++
41 lines
717 B
C++
// This tests hard situations for throwing, including the case where an
|
|
// exception is active in more than one handler at a time (ie, it needs
|
|
// refcounting)
|
|
#include <cstdio>
|
|
|
|
struct foo {
|
|
int i;
|
|
foo() : i(1) { }
|
|
foo(const foo&) : i(2) {}
|
|
};
|
|
|
|
int callee(unsigned i) {
|
|
if (i < 3) throw (int)i;
|
|
if (i < 6) throw 1.0;
|
|
if (i < 9) throw foo();
|
|
return 0;
|
|
}
|
|
|
|
void rethrow() {
|
|
throw;
|
|
}
|
|
|
|
int main() {
|
|
for (unsigned i = 0; i < 10; ++i) {
|
|
try {
|
|
return callee(i);
|
|
} catch (foo &F) {
|
|
try {
|
|
rethrow();
|
|
} catch (foo &F) {
|
|
std::printf("%d: 3\n", i);
|
|
}
|
|
} catch (int) {
|
|
std::printf("%d: 1\n", i);
|
|
} catch (...) {
|
|
std::printf("%d: 2\n", i);
|
|
}
|
|
}
|
|
}
|
|
|