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