6 #define WANT_STREAM // include.h will get stream fns 27 #ifdef SimulateExceptions 31 for (Janitor* jan = JumpBase::jl->janitor; jan; jan = jan->NextJanitor)
33 JumpItem* jx = JumpBase::jl->ji;
38 longjmp(JumpBase::jl->env, 1);
41 #endif // end of simulate exceptions 55 what_error =
new char[512];
59 what_error = (
char *)
"No heap space for exception message\n";
62 AddMessage(
"\n\nAn exception has been thrown\n");
71 int l = (int)strlen(a_what);
int r = LastOne - SoFar;
72 if (l < r) { strcpy(what_error+SoFar, a_what); SoFar += l; }
75 strncpy(what_error+SoFar, a_what, r);
76 what_error[LastOne] = 0;
85 if (value == 0) { AddMessage(
"0");
return; }
86 else if (value < 0) { value = -value; negative =
true; }
87 else negative =
false;
88 int n = 0;
int v = value;
89 while (v > 0) { v /= 10;
n++; }
91 if (LastOne-SoFar <
n) { AddMessage(
"***");
return; }
93 SoFar +=
n;
n = SoFar; what_error[
n] = 0;
96 int nv = value / 10;
int rm = value - nv * 10; value = nv;
97 what_error[--
n] = (char)(rm +
'0');
99 if (negative) what_error[--
n] =
'-';
107 std::cout <<
" * " << et->entry <<
"\n";
125 #ifdef SimulateExceptions 132 do_not_link =
false; NextJanitor = 0; OnStack =
false;
134 std::cout <<
"Not added to clean-list " << (
unsigned long)
this <<
"\n";
141 std::cout <<
"Add to clean-list " << (
unsigned long)
this <<
"\n";
143 NextJanitor = JumpBase::jl->janitor; JumpBase::jl->janitor=
this;
154 std::cout <<
"Delete from clean-list " << (
unsigned long)
this <<
"\n";
156 Janitor* lastjan = JumpBase::jl->janitor;
157 if (
this == lastjan) JumpBase::jl->janitor = NextJanitor;
160 for (Janitor* jan = lastjan->NextJanitor; jan;
161 jan = lastjan->NextJanitor)
164 { lastjan->NextJanitor = jan->NextJanitor;
return; }
169 "Cannot resolve memory linked list\nSee notes in myexcept.cpp for details\n" 202 JumpItem* JumpBase::jl;
203 jmp_buf JumpBase::env;
204 bool Janitor::do_not_link;
207 int JanitorInitializer::ref_count;
209 JanitorInitializer::JanitorInitializer()
211 if (ref_count++ == 0)
new JumpItem;
215 #endif // end of SimulateExceptions 222 std::cout <<
"\n\nThere has been an exception with no handler - exiting";
224 if (what) std::cout << what <<
"\n";
233 FreeCheckLink::FreeCheckLink() : next(FreeCheck::next)
234 { FreeCheck::next =
this; }
236 FCLClass::FCLClass(
void* t,
char* name) : ClassName(name) { ClassStore=t; }
238 FCLRealArray::FCLRealArray(
void* t,
char* o,
int s)
239 : Operation(o),
size(s) { ClassStore=t; }
241 FCLIntArray::FCLIntArray(
void* t,
char* o,
int s)
242 : Operation(o),
size(s) { ClassStore=t; }
244 FreeCheckLink* FreeCheck::next;
245 int FreeCheck::BadDelete;
247 void FCLClass::Report()
248 { std::cout <<
" " << ClassName <<
" " << (
unsigned long)ClassStore <<
"\n"; }
250 void FCLRealArray::Report()
252 std::cout <<
" " << Operation <<
" " << (
unsigned long)ClassStore <<
256 void FCLIntArray::Report()
258 std::cout <<
" " << Operation <<
" " << (
unsigned long)ClassStore <<
262 void FreeCheck::Register(
void* t,
char* name)
264 FCLClass* f =
new FCLClass(t,name);
265 if (!f) { std::cout <<
"Out of memory in FreeCheck\n"; exit(1); }
267 std::cout <<
"Registering " << name <<
" " << (
unsigned long)t <<
"\n";
271 void FreeCheck::RegisterR(
void* t,
char* o,
int s)
273 FCLRealArray* f =
new FCLRealArray(t,o,s);
274 if (!f) { std::cout <<
"Out of memory in FreeCheck\n"; exit(1); }
276 std::cout << o <<
" " << s <<
" " << (
unsigned long)t <<
"\n";
280 void FreeCheck::RegisterI(
void* t,
char* o,
int s)
282 FCLIntArray* f =
new FCLIntArray(t,o,s);
283 if (!f) { std::cout <<
"Out of memory in FreeCheck\n"; exit(1); }
285 std::cout << o <<
" " << s <<
" " << (
unsigned long)t <<
"\n";
289 void FreeCheck::DeRegister(
void* t,
char* name)
291 FreeCheckLink* last = 0;
293 std::cout <<
"Deregistering " << name <<
" " << (
unsigned long)t <<
"\n";
295 for (FreeCheckLink* fcl = next; fcl; fcl = fcl->next)
297 if (fcl->ClassStore==t)
299 if (last) last->next = fcl->next;
else next = fcl->next;
304 std::cout <<
"\nRequest to delete non-existent object of class and location:\n";
305 std::cout <<
" " << name <<
" " << (
unsigned long)t <<
"\n";
311 void FreeCheck::DeRegisterR(
void* t,
char* o,
int s)
313 FreeCheckLink* last = 0;
315 std::cout << o <<
" " << s <<
" " << (
unsigned long)t <<
"\n";
317 for (FreeCheckLink* fcl = next; fcl; fcl = fcl->next)
319 if (fcl->ClassStore==t)
321 if (last) last->next = fcl->next;
else next = fcl->next;
322 if (s >= 0 && ((FCLRealArray*)fcl)->size != s)
324 std::cout <<
"\nArray sizes do not agree:\n";
325 std::cout <<
" " << o <<
" " << (
unsigned long)t
326 <<
" " << ((FCLRealArray*)fcl)->
size <<
" " << s <<
"\n";
334 std::cout <<
"\nRequest to delete non-existent real array:\n";
335 std::cout <<
" " << o <<
" " << (
unsigned long)t <<
" " << s <<
"\n";
341 void FreeCheck::DeRegisterI(
void* t,
char* o,
int s)
343 FreeCheckLink* last = 0;
345 std::cout << o <<
" " << s <<
" " << (
unsigned long)t <<
"\n";
347 for (FreeCheckLink* fcl = next; fcl; fcl = fcl->next)
349 if (fcl->ClassStore==t)
351 if (last) last->next = fcl->next;
else next = fcl->next;
352 if (s >= 0 && ((FCLIntArray*)fcl)->size != s)
354 std::cout <<
"\nArray sizes do not agree:\n";
355 std::cout <<
" " << o <<
" " << (
unsigned long)t
356 <<
" " << ((FCLIntArray*)fcl)->
size <<
" " << s <<
"\n";
364 std::cout <<
"\nRequest to delete non-existent int array:\n";
365 std::cout <<
" " << o <<
" " << (
unsigned long)t <<
" " << s <<
"\n";
371 void FreeCheck::Status()
375 std::cout <<
"\nObjects of the following classes remain undeleted:\n";
376 for (FreeCheckLink* fcl = next; fcl; fcl = fcl->next) fcl->Report();
379 else std::cout <<
"\nNo objects remain undeleted\n\n";
382 std::cout <<
"\nThere were " << BadDelete <<
383 " requests to delete non-existent items\n\n";
387 #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
os2<< "> n<< " > nendobj n
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)