31 using namespace basis;
48 return application_configuration::get_logging_directory();
55 #if defined(__UNIX__) || defined(__GNU_WINDOWS__)
60 #pragma error("hmmm: no code for error number for this operating system")
67 #if defined(__UNIX__) || defined(__GNU_WINDOWS__)
68 return strerror(to_name);
83 #pragma error("hmmm: no code for error text for this operating system")
88 astring critical_events::critical_events_directory()
90 static bool initted =
false;
98 return hidden_critical_events_dir();
101 void critical_events::set_critical_events_directory(
const astring &directory)
102 { hidden_critical_events_dir() = directory; }
104 void critical_events::write_to_critical_events(
const char *to_write)
106 astring filename = critical_events_directory();
107 filename +=
"/runtime_issues.log";
108 FILE *errfile = fopen(filename.
s(),
"ab");
110 astring app_name = application_configuration::application_name();
111 int indy = app_name.
find(
'/', app_name.
end(),
true);
113 indy = app_name.
find(
'\\', app_name.
end(),
true);
115 fprintf(errfile,
"%s [%s]:%s", time_stamp::notarize(
true).s(),
116 app_name.
s(), parser_bits::platform_eol_to_chars());
117 fprintf(errfile,
"%s%s", to_write, parser_bits::platform_eol_to_chars());
122 void critical_events::write_to_console(
const char *guards_message_space)
123 { fprintf(stderr,
"%s", (
char *)guards_message_space); fflush(stderr); }
125 void critical_events::alert_message(
const char *info,
const char *title)
129 const char border =
'=';
130 to_print +=
astring(border,
int(strlen(title)) + 4);
131 to_print += parser_bits::platform_eol_to_chars();
137 to_print += parser_bits::platform_eol_to_chars();
138 to_print +=
astring(border,
int(strlen(title)) + 4);
139 to_print += parser_bits::platform_eol_to_chars();
143 program_wide_logger::get().log(to_print, ALWAYS_PRINT);
147 void critical_events::alert_message(
const astring &info) { alert_message(info.
s()); }
150 { alert_message(info.
s(), title.
s()); }
152 void critical_events::make_error_message(
const char *file,
int line,
153 const char *error_class,
const char *error_function,
154 const char *info,
char *guards_message_space)
156 strcpy(guards_message_space,
"\nProblem reported for \"");
161 strcat(guards_message_space, error_class);
162 strcat(guards_message_space,
"::");
163 strcat(guards_message_space, error_function);
164 strcat(guards_message_space,
"\"\n(invoked at line ");
166 sprintf(line_num,
"%d", line);
167 strcat(guards_message_space, line_num);
168 strcat(guards_message_space,
" in ");
169 strcat(guards_message_space, file);
170 strcat(guards_message_space,
" at ");
171 strcat(guards_message_space, time_stamp::notarize(
false).s());
172 strcat(guards_message_space,
")\n");
173 strcat(guards_message_space, info);
174 strcat(guards_message_space,
"\n\n\n");
177 void critical_events::FL_deadly_error(
const char *file,
int line,
const char *error_class,
178 const char *error_function,
const char *info)
180 FL_continuable_error(file, line, error_class, error_function, info,
181 "Deadly Error Information");
183 throw "deadly_error";
189 void critical_events::FL_deadly_error(
const astring &file,
int line,
193 FL_deadly_error(file.
s(), line, error_class.
s(), error_function.
s(),
197 void critical_events::FL_continuable_error_real(
const char *file,
int line,
198 const char *error_class,
const char *error_function,
const char *info,
208 make_error_message(file, line, error_class, error_function, info,
209 guards_message_space);
210 alert_message(guards_message_space, title);
213 void critical_events::FL_continuable_error(
const char *file,
int line,
214 const char *error_class,
const char *error_function,
const char *info,
217 FL_continuable_error_real(file, line, error_class, error_function, info, title);
220 void critical_events::FL_continuable_error(
const astring &file,
int line,
224 FL_continuable_error_real(file.
s(), line, error_class.
s(),
225 error_function.
s(), info.
s(), title.
s());
228 void critical_events::FL_non_continuable_error(
const char *file,
int line,
229 const char *error_class,
const char *error_function,
const char *info,
232 FL_continuable_error_real(file, line, error_class, error_function, info,
237 void critical_events::FL_non_continuable_error(
const astring &file,
int line,
241 FL_continuable_error_real(file.
s(), line, error_class.
s(),
242 error_function.
s(), info.
s(), title.
s());
246 void critical_events::FL_console_error(
const char *file,
int line,
const char *error_class,
247 const char *error_function,
const char *info)
250 make_error_message(file, line, error_class, error_function, info,
251 guards_message_space);
252 write_to_console(guards_message_space);
255 void critical_events::FL_out_of_memory_now(
const char *file,
int line,
256 const char *the_class_name,
const char *the_func)
258 FL_non_continuable_error(file, line, the_class_name, the_func,
259 "Program stopped due to memory allocation failure.",
260 "Out of Memory Now");
263 void critical_events::implement_bounds_halt(
const char *the_class_name,
const char *the_func,
264 const char *value,
const char *low,
const char *high,
265 const char *error_addition)
268 strcpy(message,
"bounds error caught");
269 strcat(message, error_addition);
270 strcat(message,
":\r\n");
271 strcat(message, value);
272 strcat(message,
" is not between ");
273 strcat(message, low);
274 strcat(message,
" and ");
275 strcat(message, high);
276 #ifdef ERRORS_ARE_FATAL
Provides a dynamically resizable ASCII character string.
const char * s() const
synonym for observe. the 's' stands for "string", if that helps.
virtual void zap(int start, int end)
Deletes the characters between "start" and "end" inclusively.
int end() const
returns the index of the last (non-null) character in the string.
int find(char to_find, int position=0, bool reverse=false) const
Locates "to_find" in "this".
auto_synchronizer simplifies concurrent code by automatically unlocking.
Provides a means of logging events for runtime problems.
const int MESSAGE_SPACE_PROVIDED
#define continuable_error(c, f, i)
#define deadly_error(c, f, i)
#define CAUSE_BREAKPOINT
This macro wraps the notion of stopping in the debugger.
#define NULL_POINTER
The value representing a pointer to nothing.
The guards collection helps in testing preconditions and reporting errors.
bool non_negative(const type &a)
non_negative returns true if "a" is greater than or equal to zero.
unsigned int un_int
Abbreviated name for unsigned integers.
A logger that sends to the console screen using the standard output device.
astring default_critical_location()
A dynamic container class that holds any kind of object via pointers.
#define SAFE_STATIC(type, func_name, parms)
Statically defines a singleton object whose scope is the program's lifetime.
Aids in achievement of platform independence.