1 // $XConsortium: Exceptions.hh /main/4 1996/07/05 15:16:42 rws $
5 #define _Exceptions_hh_active
8 #define MIN(x, y) (((x) < (y)) ? (x) : (y))
11 #ifndef NATIVE_EXCEPTIONS
12 #define NATIVE_EXCEPTIONS
14 #define Exception mException
17 #ifndef NATIVE_EXCEPTIONS
30 #ifndef NATIVE_EXCEPTIONS
32 #define PRINTF(MSG) printf MSG
47 #if !defined(__STDC__) && !defined(hpux)
48 #define STRINGIFY(S) "S"
50 #define STRINGIFY(S) #S
54 #ifndef UNUSED_VARIABLE
55 # if defined(__GNUC__)
56 # define UNUSED_VARIABLE(x) x __attribute__((unused))
57 # elif defined(__LCLINT__)
58 # define UNUSED_VARIABLE(x) /*@unused@*/ x
60 # define UNUSED_VARIABLE(x) x
64 #endif /* NATIVE_EXCEPTIONS */
66 #include "terminate.hh"
67 #include "Destructable.hh"
68 #include "Exception.hh"
70 #ifdef NATIVE_EXCEPTIONS
72 #define INIT_EXCEPTIONS()
74 #define mthrow(OBJ) throw OBJ
79 #define mcatch_any() catch(...)
80 #define mcatch_noarg(OBJ) catch(OBJ)
81 #define mcatch(TYPE,OBJ) catch(TYPE OBJ)
87 // This macro, which should be the first thing in main, establishes a jump
88 // environment for the context of the entire program.
90 #define INIT_EXCEPTIONS() \
91 { int __stack_start; Exceptions::initialize (&__stack_start); }
97 Jump_Environment __jump_env; \
98 if (setjmp (__jump_env.f_env) == 0) {
104 #define DEBUG_THROW_FLAG 1
106 #define DEBUG_THROW_FLAG 0
109 // This works if OBJ is an object or a pointer since Exception objects
110 // overload operator ->.
111 #if !defined(hpux) && !defined(USL)
112 #define mthrow(OBJ) \
113 (OBJ)->throw_it (__LINE__, __FILE__, DEBUG_THROW_FLAG)
115 #define mthrow(OBJ) \
116 OBJ->throw_it (__LINE__, __FILE__, DEBUG_THROW_FLAG)
120 Exception::current_exception().do_throw (__LINE__, __FILE__)
125 #define PRINT_CATCH \
126 fprintf (stderr, "Application caught exception:\n"); \
127 fprintf (stderr, " Thrown from file \"%s\", line %d\n", \
128 Exception::current_exception().file(), \
129 Exception::current_exception().line()); \
130 fprintf (stderr, " Caught in file \"%s\", line %d.\n", \
136 #define mcatch_any() \
140 #define mcatch_noarg(OBJ) \
141 } else if (Exception::current_exception().isa (STRINGIFY(OBJ))) { \
144 #define mcatch(TYPE,OBJ) \
145 mcatch_noarg (TYPE) \
146 TYPE UNUSED_VARIABLE(OBJ) = (TYPE) Exception::current_exception();
157 typedef void (*error_handler_t) (const char *[], int);
159 static void initialize (void *ptr);
161 // Error handling stuff (message appear below).
162 enum error_type_t { INTERNAL_ERROR, APPLICATION_ERROR, THROW_MESSAGE };
163 static void error (const char *, error_type_t);
164 static error_handler_t set_error_handler (error_handler_t);
167 friend class Destructable;
168 friend class Jump_Environment;
169 friend class Unwind_Stack;
170 friend class Exception;
171 friend void terminate();
173 static void check_initialized();
175 protected: // variables
176 // function pointer to error message handler
177 static error_handler_t g_error_handler;
180 static char *f_msg_internal_error;
181 static char *f_msg_application_error;
182 static char *f_msg_throw_message;
185 static char *f_msg_not_initialized;
186 static char *f_msg_initialized_twice;
187 static char *f_msg_not_caught;
188 static char *f_msg_no_current_exception;
189 static char *f_msg_throw_from_terminate;
190 static char *f_msg_throw_from_error_handler;
191 static char *f_msg_throw_from_destructor;
192 static char *f_msg_throw_ptr_to_stack;
194 // Internal memory errors.
195 static char *f_msg_out_of_exception_memory;
196 static char *f_msg_out_of_obj_stack_memory;
197 static char *f_msg_memory_already_freed;
200 friend void initialize_exception();
201 friend void quit_exception();
205 // includes for inline functions
207 #include "Jump_Environment.hh"
208 #include "Destructable_il.hh"
210 #endif /* NATIVE_EXCEPTIONS */
212 #undef _Exceptions_hh_active
214 #endif /* _Exceptions_hh */
215 /* DO NOT ADD ANY LINES AFTER THIS #endif */