blob: f80f0eeaaba6389825c89582193313420cc74ab9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
// This tests that exception specifications interact properly with unexpected
// handlers.
#include <exception>
#include <stdio.h>
#include <stdlib.h>
static void TerminateHandler() {
printf("std::terminate called\n");
exit(1);
}
static void UnexpectedHandler1() {
printf("std::unexpected called: throwing a double\n");
throw 1.0;
}
static void UnexpectedHandler2() {
printf("std::unexpected called: throwing an int!\n");
throw 1;
}
void test(bool Int) throw (double) {
if (Int) {
printf("Throwing an int from a function which only allows doubles!\n");
throw 1;
} else {
printf("Throwing a double from a function which allows doubles!\n");
throw 1.0;
}
}
int main() {
try {
test(false);
} catch (double D) {
printf("Double successfully caught!\n");
}
std::set_terminate(TerminateHandler);
std::set_unexpected(UnexpectedHandler1);
try {
test(true);
} catch (double D) {
printf("Double successfully caught!\n");
}
std::set_unexpected(UnexpectedHandler2);
test(true);
}
|