4 #define G_TEMP_SPACE_SIZE 1024
8 class Exception : public Destructable
11 #ifdef NATIVE_EXCEPTIONS
20 #if defined(linux) && defined(EXC_DEBUG)
23 PRINTF (("Destroying Exception @ %p\n", this));
25 #elif defined(EXC_DEBUG)
28 PRINTF (("Destroying Exception @ %p\n", this));
32 // For printing debugging info. Can be overloaded by derived classes.
33 virtual void print_exception()
36 virtual const char *class_name()
37 { return ("Exception"); }
39 Exception *prepare_to_throw();
41 // This operator invoked if this is thrown as an object/reference
42 Exception *operator ->()
43 { if (!f_thrown) f_thrown_as_pointer = 0;
46 operator Exception *()
49 virtual int isa (const char *type)
50 { return (is (type, "Exception")); }
52 int is (const char *type, const char *this_class);
54 static Exception ¤t_exception();
61 // Need to provide a plain operator new definition because we
62 // have a definition of the other one below. (See the ARM.)
65 static void *operator new (size_t size)
66 { return (::operator new (size)); }
69 static void operator delete (void *place);
71 // For initial throw. Redefined by decendents.
72 // Makes temporaries for stack based objects and calls do_throw.
73 void throw_it (unsigned int line, const char *file, int debugging);
75 // Actual throw code. Also used for rethrows.
76 void do_throw (unsigned int line = 0,
77 const char *file = "(unknown)",
80 // Length is only valid for exceptions at the top of the stack!
81 int length() { return (g_next_avail - (char *) this); }
82 void unmake_current();
84 static void relocate (Exception **exception, int length);
87 friend class Jump_Environment;
88 friend class Exceptions;
90 #if defined(hpux)||defined(__uxp__)
91 #define MakeOperatorNewPublic
94 #ifdef MakeOperatorNewPublic
95 // A problem with the HP-UX 3.65 compiler requires us to make this public.
96 // And, since we gen the Templates.nd.c file on a non-HPUX platform, we need
97 // a second way to trigger the change.
100 static void *operator new (size_t size, int);
101 #ifdef MakeOperatorNewPublic
105 // f_thrown flag is a safty feature to make sure that the f_throw_as_pointer
106 // flag can't be reset accidently by the user calling operator ->
109 unsigned char f_thrown;
110 unsigned char f_thrown_as_pointer;
111 unsigned char f_temporary;
113 unsigned char f_thrown : 1;
114 unsigned char f_thrown_as_pointer : 1;
115 unsigned char f_temporary : 1;
119 // Line and file where exception was originally thrown from.
121 unsigned short f_line;
122 Exception *f_previous_exception;
124 static Exception *g_current_exception;
127 static char *g_temp_space;
129 static char g_temp_space[G_TEMP_SPACE_SIZE];
132 static char *g_next_avail;
135 friend void initialize_exception();
136 friend void quit_exception();
139 #endif /* NATIVE_EXCEPTIONS */
143 // /////////////////////////////////////////////////////////////////
144 // DECLARE_EXCEPTION - macros for derived classes
145 // /////////////////////////////////////////////////////////////////
147 #ifndef NATIVE_EXCEPTIONS
148 // NOTE: class_name, is, and isa should be renamed to _exc_...
150 #define _DECL_START(NAME) \
151 const char *class_name() \
152 { return (STRINGIFY(NAME)); } \
153 void throw_it (unsigned int line, const char *file, int dbg) \
156 temp = new (0) NAME (*this); \
157 ((NAME *)temp)->f_temporary = 1; \
160 temp->do_throw (line, file, dbg); } \
161 NAME *operator ->() { if (!f_thrown) f_thrown_as_pointer = 0; \
163 operator NAME *() { return (this); } \
164 int isa (const char *type) \
165 { return (is (type, STRINGIFY(NAME)) ||
170 // MUST be the first thing in a subclass or protections get screwed up.
172 #define DECLARE_EXCEPTION DECLARE_EXCEPTION1
174 #define DECLARE_EXCEPTION1(NAME,SUPER1) \
179 #define DECLARE_EXCEPTION2(NAME,SUPER1,SUPER2) \
181 SUPER1::isa (type) || \
185 #define DECLARE_EXCEPTION3(NAME,SUPER1,SUPER2,SUPER3) \
187 SUPER1::isa (type) || \
188 SUPER2::isa (type) || \
194 #define DECLARE_EXCEPTION(NAME,SUPER1)
195 #define DECLARE_EXCEPTION1(NAME,SUPER1)
196 #define DECLARE_EXCEPTION2(NAME,SUPER1,SUPER2)
197 #define DECLARE_EXCEPTION3(NAME,SUPER1,SUPER2)
199 #endif /* NATIVE_EXCEPTIONS */
201 // Users can define more if they need to...