41 TVirtualMutex *gErrorMutex = 0;
43 Int_t gErrorIgnoreLevel = kUnset;
44 Int_t gErrorAbortLevel = kSysError+1;
45 Bool_t gPrintViaErrorHandler = kFALSE;
47 const char *kAssertMsg =
"%s violated at line %d of `%s'";
48 const char *kCheckMsg =
"%s not true at line %d of `%s'";
53 static const char *__crashreporter_info__ = 0;
54 asm(
".desc ___crashreporter_info__, 0x10");
58 static ErrorHandlerFunc_t gErrorHandler = DefaultErrorHandler;
64 static void DebugPrint(
const char *fmt, ...)
66 TTHREAD_TLS(Int_t) buf_size = 2048;
67 TTHREAD_TLS(
char*) buf = 0;
74 buf = new
char[buf_size];
76 Int_t n = vsnprintf(buf, buf_size, fmt, ap);
79 if (n == -1 || n >= buf_size) {
93 R__LOCKGUARD2(gErrorMutex);
95 const char *toprint = buf;
96 fprintf(stderr,
"%s", toprint);
99 ::OutputDebugString(buf);
106 ErrorHandlerFunc_t SetErrorHandler(ErrorHandlerFunc_t newhandler)
108 ErrorHandlerFunc_t oldhandler = gErrorHandler;
109 gErrorHandler = newhandler;
116 ErrorHandlerFunc_t GetErrorHandler()
118 return gErrorHandler;
125 void DefaultErrorHandler(Int_t level, Bool_t abort_bool,
const char *location,
const char *msg)
127 if (gErrorIgnoreLevel == kUnset) {
128 R__LOCKGUARD2(gErrorMutex);
130 gErrorIgnoreLevel = 0;
132 TString slevel = gEnv->GetValue(
"Root.ErrorIgnoreLevel",
"Print");
133 if (!slevel.CompareTo(
"Print", TString::kIgnoreCase))
134 gErrorIgnoreLevel = kPrint;
135 else if (!slevel.CompareTo(
"Info", TString::kIgnoreCase))
136 gErrorIgnoreLevel = kInfo;
137 else if (!slevel.CompareTo(
"Warning", TString::kIgnoreCase))
138 gErrorIgnoreLevel = kWarning;
139 else if (!slevel.CompareTo(
"Error", TString::kIgnoreCase))
140 gErrorIgnoreLevel = kError;
141 else if (!slevel.CompareTo(
"Break", TString::kIgnoreCase))
142 gErrorIgnoreLevel = kBreak;
143 else if (!slevel.CompareTo(
"SysError", TString::kIgnoreCase))
144 gErrorIgnoreLevel = kSysError;
145 else if (!slevel.CompareTo(
"Fatal", TString::kIgnoreCase))
146 gErrorIgnoreLevel = kFatal;
150 if (level < gErrorIgnoreLevel)
153 const char *type = 0;
157 if (level >= kWarning)
162 type =
"\n *** Break ***";
163 if (level >= kSysError)
169 if (level >= kPrint && level < kInfo)
170 smsg.Form(
"%s", msg);
171 else if (level >= kBreak && level < kSysError)
172 smsg.Form(
"%s %s", type, msg);
173 else if (!location || !location[0])
174 smsg.Form(
"%s: %s", type, msg);
176 smsg.Form(
"%s in <%s>: %s", type, location, msg);
178 DebugPrint(
"%s\n", smsg.Data());
184 if (__crashreporter_info__)
185 delete [] __crashreporter_info__;
186 __crashreporter_info__ = StrDup(smsg);
189 DebugPrint(
"aborting\n");
192 gSystem->StackTrace();
202 void ErrorHandler(Int_t level,
const char *location,
const char *fmt, va_list ap)
204 TTHREAD_TLS(Int_t) buf_size(256);
205 TTHREAD_TLS(
char*) buf_storage(0);
208 char *buf = buf_storage ? buf_storage : small_buf;
216 buf_storage = buf =
new char[buf_size];
220 fmt =
"no error message provided";
222 Int_t n = vsnprintf(buf, buf_size, fmt, ap);
225 if (n == -1 || n >= buf_size) {
230 if (buf != &(small_buf[0]))
delete [] buf;
242 if (level >= kSysError && level < kFatal) {
243 const char *toprint = buf;
244 bp = Form(
"%s (%s)", toprint, gSystem->GetError());
249 gErrorHandler(level, level >= gErrorAbortLevel, location, bp);
251 gErrorHandler(level, kTRUE, location, bp);
260 void AbstractMethod(
const char *method)
262 Warning(method,
"this method must be overridden!");
269 void MayNotUse(
const char *method)
271 Warning(method,
"may not use this method");
278 void Obsolete(
const char *
function,
const char *asOfVers,
const char *removedFromVers)
281 mess.Form(
"obsolete as of %s and will be removed from %s", asOfVers, removedFromVers);
282 Warning(
function,
"%s", mess.Data());
288 void Error(
const char *location,
const char *va_(fmt), ...)
291 va_start(ap,va_(fmt));
292 ErrorHandler(kError, location, va_(fmt), ap);
299 void SysError(
const char *location,
const char *va_(fmt), ...)
302 va_start(ap, va_(fmt));
303 ErrorHandler(kSysError, location, va_(fmt), ap);
310 void Break(
const char *location,
const char *va_(fmt), ...)
313 va_start(ap,va_(fmt));
314 ErrorHandler(kBreak, location, va_(fmt), ap);
321 void Info(
const char *location,
const char *va_(fmt), ...)
324 va_start(ap,va_(fmt));
325 ErrorHandler(kInfo, location, va_(fmt), ap);
332 void Warning(
const char *location,
const char *va_(fmt), ...)
335 va_start(ap,va_(fmt));
336 ErrorHandler(kWarning, location, va_(fmt), ap);
346 void Fatal(
const char *location,
const char *va_(fmt), ...)
349 va_start(ap,va_(fmt));
350 ErrorHandler(kFatal, location, va_(fmt), ap);