Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
STD_BAD_EXCEPTION.cpp
Go to the documentation of this file.
1// checking for class std::bad_exception
2
3
25#include "config.h"
26
27#ifndef _RWSTD_NO_HONOR_STD
28# ifdef _RWSTD_NO_STD_TERMINATE
29# include "terminate.h"
30# endif // _RWSTD_NO_STD_TERMINATE
31#endif // _RWSTD_NO_HONOR_STD
32
33
34#ifndef _RWSTD_NO_EXCEPTION_SPECIFICATION
35# define throws(args) throw args
36#else
37# define throws(ignore)
38#endif // _RWSTD_NO_EXCEPTION_SPECIFICATION
39
40
41#ifndef _RWSTD_NO_STD_SET_UNEXPECTED
42
43namespace std {
44
45#endif // _RWSTD_NO_STD_SET_UNEXPECTED
46
47
48typedef void (*unexpected_handler)();
49unexpected_handler set_unexpected (void (*)()) throws (());
50
51
52#ifndef _RWSTD_NO_STD_SET_UNEXPECTED
53
54} // std
55
56# define SET_UNEXPECTED(handler) std::set_unexpected (handler)
57
58#else
59
60# define SET_UNEXPECTED(handler) set_unexpected (handler)
61
62#endif // _RWSTD_NO_STD_SET_UNEXPECTED
63
64namespace std {
65
66class bad_exception { };
67
68} // namespace std
69
70
71// will fail if namespace std is not honored
73
74
76{
77 // throw an object of a disallowed type
78 throw 0;
79}
80
81void handler ()
82{
83 // throw an object of a type not allowed by the exception-specification
84 // of the function that already violated its specification (due to which
85 // the handler has been called); this requires the exception object to be
86 // replaced by the runtime library by one of type [std]::bad_exception
87 throw "";
88}
89
90int main ()
91{
93
94 try {
95 // will fail if runtime library doesn't recognize std::::bad_exception
96 // by calling terminate()
97 foo ();
98 }
99 catch (std::bad_exception&) {
100 return 0;
101 }
102 catch (...) {
103 return 1;
104 }
105
106 // runtime library is broken
107 return 2;
108}
void(* unexpected_handler)()
void handler()
#define throws(args)
#define SET_UNEXPECTED(handler)
void foo()
int main()
int set_unexpected()
Definition json.h:5363