16 #define WANT_STREAM // include.h will get stream fns 25 namespace RBD_COMMON {
33 #ifdef SimulateExceptions 37 for (
Janitor* jan = JumpBase::jl->janitor; jan; jan = jan->NextJanitor)
39 JumpItem* jx = JumpBase::jl->ji;
44 longjmp(JumpBase::jl->env, 1);
47 #endif // end of simulate exceptions 61 what_error =
new char[512];
65 what_error = (
char *)
"No heap space for exception message\n";
68 AddMessage(
"\n\nAn exception has been thrown\n");
77 int l = strlen(a_what);
int r = LastOne - SoFar;
78 if (l < r) { strcpy(what_error+SoFar, a_what); SoFar += l; }
81 strncpy(what_error+SoFar, a_what, r);
82 what_error[LastOne] = 0;
91 if (value == 0) { AddMessage(
"0");
return; }
92 else if (value < 0) { value = -value; negative =
true; }
93 else negative =
false;
94 int n = 0;
int v = value;
95 while (v > 0) { v /= 10; n++; }
97 if (LastOne-SoFar < n) { AddMessage(
"***");
return; }
99 SoFar += n; n = SoFar; what_error[n] = 0;
102 int nv = value / 10;
int rm = value - nv * 10; value = nv;
103 what_error[--n] = (char)(rm +
'0');
105 if (negative) what_error[--n] =
'-';
113 cout <<
" * " << et->entry <<
"\n";
131 #ifdef SimulateExceptions 138 do_not_link =
false; NextJanitor = 0; OnStack =
false;
140 cout <<
"Not added to clean-list " << (
unsigned long)
this <<
"\n";
147 cout <<
"Add to clean-list " << (
unsigned long)
this <<
"\n";
149 NextJanitor = JumpBase::jl->janitor; JumpBase::jl->janitor=
this;
160 cout <<
"Delete from clean-list " << (
unsigned long)
this <<
"\n";
162 Janitor* lastjan = JumpBase::jl->janitor;
163 if (
this == lastjan) JumpBase::jl->janitor = NextJanitor;
166 for (
Janitor* jan = lastjan->NextJanitor; jan;
167 jan = lastjan->NextJanitor)
170 { lastjan->NextJanitor = jan->NextJanitor;
return; }
175 "Cannot resolve memory linked list\nSee notes in myexcept.cpp for details\n" 208 JumpItem* JumpBase::jl;
209 jmp_buf JumpBase::env;
210 bool Janitor::do_not_link;
213 int JanitorInitializer::ref_count;
215 JanitorInitializer::JanitorInitializer()
217 if (ref_count++ == 0)
new JumpItem;
221 #endif // end of SimulateExceptions 228 cout <<
"\n\nThere has been an exception with no handler - exiting";
230 if (what) cout << what <<
"\n";
239 FreeCheckLink::FreeCheckLink() : next(FreeCheck::next)
240 { FreeCheck::next =
this; }
242 FCLClass::FCLClass(
void* t,
char* name) : ClassName(name) { ClassStore=t; }
244 FCLRealArray::FCLRealArray(
void* t,
char* o,
int s)
245 : Operation(o),
size(s) { ClassStore=t; }
247 FCLIntArray::FCLIntArray(
void* t,
char* o,
int s)
248 : Operation(o),
size(s) { ClassStore=t; }
250 FreeCheckLink* FreeCheck::next;
251 int FreeCheck::BadDelete;
253 void FCLClass::Report()
254 { cout <<
" " << ClassName <<
" " << (
unsigned long)ClassStore <<
"\n"; }
256 void FCLRealArray::Report()
258 cout <<
" " << Operation <<
" " << (
unsigned long)ClassStore <<
262 void FCLIntArray::Report()
264 cout <<
" " << Operation <<
" " << (
unsigned long)ClassStore <<
268 void FreeCheck::Register(
void* t,
char* name)
270 FCLClass* f =
new FCLClass(t,name);
271 if (!f) { cout <<
"Out of memory in FreeCheck\n"; exit(1); }
273 cout <<
"Registering " << name <<
" " << (
unsigned long)t <<
"\n";
277 void FreeCheck::RegisterR(
void* t,
char* o,
int s)
279 FCLRealArray* f =
new FCLRealArray(t,o,s);
280 if (!f) { cout <<
"Out of memory in FreeCheck\n"; exit(1); }
282 cout << o <<
" " << s <<
" " << (
unsigned long)t <<
"\n";
286 void FreeCheck::RegisterI(
void* t,
char* o,
int s)
288 FCLIntArray* f =
new FCLIntArray(t,o,s);
289 if (!f) { cout <<
"Out of memory in FreeCheck\n"; exit(1); }
291 cout << o <<
" " << s <<
" " << (
unsigned long)t <<
"\n";
295 void FreeCheck::DeRegister(
void* t,
char* name)
297 FreeCheckLink* last = 0;
299 cout <<
"Deregistering " << name <<
" " << (
unsigned long)t <<
"\n";
301 for (FreeCheckLink* fcl = next; fcl; fcl = fcl->next)
303 if (fcl->ClassStore==t)
305 if (last) last->next = fcl->next;
else next = fcl->next;
310 cout <<
"\nRequest to delete non-existent object of class and location:\n";
311 cout <<
" " << name <<
" " << (
unsigned long)t <<
"\n";
317 void FreeCheck::DeRegisterR(
void* t,
char* o,
int s)
319 FreeCheckLink* last = 0;
321 cout << o <<
" " << s <<
" " << (
unsigned long)t <<
"\n";
323 for (FreeCheckLink* fcl = next; fcl; fcl = fcl->next)
325 if (fcl->ClassStore==t)
327 if (last) last->next = fcl->next;
else next = fcl->next;
328 if (s >= 0 && ((FCLRealArray*)fcl)->size != s)
330 cout <<
"\nArray sizes do not agree:\n";
331 cout <<
" " << o <<
" " << (
unsigned long)t
332 <<
" " << ((FCLRealArray*)fcl)->
size <<
" " << s <<
"\n";
340 cout <<
"\nRequest to delete non-existent real array:\n";
341 cout <<
" " << o <<
" " << (
unsigned long)t <<
" " << s <<
"\n";
347 void FreeCheck::DeRegisterI(
void* t,
char* o,
int s)
349 FreeCheckLink* last = 0;
351 cout << o <<
" " << s <<
" " << (
unsigned long)t <<
"\n";
353 for (FreeCheckLink* fcl = next; fcl; fcl = fcl->next)
355 if (fcl->ClassStore==t)
357 if (last) last->next = fcl->next;
else next = fcl->next;
358 if (s >= 0 && ((FCLIntArray*)fcl)->size != s)
360 cout <<
"\nArray sizes do not agree:\n";
361 cout <<
" " << o <<
" " << (
unsigned long)t
362 <<
" " << ((FCLIntArray*)fcl)->
size <<
" " << s <<
"\n";
370 cout <<
"\nRequest to delete non-existent int array:\n";
371 cout <<
" " << o <<
" " << (
unsigned long)t <<
" " << s <<
"\n";
377 void FreeCheck::Status()
381 cout <<
"\nObjects of the following classes remain undeleted:\n";
382 for (FreeCheckLink* fcl = next; fcl; fcl = fcl->next) fcl->Report();
385 else cout <<
"\nNo objects remain undeleted\n\n";
388 cout <<
"\nThere were " << BadDelete <<
389 " requests to delete non-existent items\n\n";
393 #endif // end of DO_FREE_CHECK
static void AddMessage(const char *a_what)
static unsigned long Select
static unsigned long Select
static unsigned long Select
Invalid_argument(const char *a_what=0)
Out_of_range(const char *a_what=0)
Domain_error(const char *a_what=0)
static unsigned long Select
Bad_alloc(const char *a_what=0)
static unsigned long Select
static unsigned long Select
static unsigned long Select
static unsigned long Select
Runtime_error(const char *a_what=0)
Overflow_error(const char *a_what=0)
Range_error(const char *a_what=0)
static const char * what()
static void AddInt(int value)
static unsigned long Select
Logic_error(const char *a_what=0)
BaseException(const char *a_what=0)
static unsigned long Select
Length_error(const char *a_what=0)