Logo ROOT  
Reference Guide
TError.h
Go to the documentation of this file.
1 // @(#)root/base:$Id$
2 // Author: Fons Rademakers 29/07/95
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOT_TError
13 #define ROOT_TError
14 
15 
16 //////////////////////////////////////////////////////////////////////////
17 // //
18 // Error handling routines. //
19 // //
20 // This file defines a number of global error handling routines: //
21 // Warning(), Error(), SysError() and Fatal(). They all take a //
22 // location string (where the error happened) and a printf style format //
23 // string plus vararg's. In the end these functions call an //
24 // errorhanlder function. Initially, a minimal, non thread-safe handler //
25 // is installed that is supposed to be replaced by the //
26 // DefaultErrorHandler(), which needs to be implemented and installed //
27 // by the user of TError. Normally, the default error handler is set //
28 // during gROOT initialization. //
29 // //
30 //////////////////////////////////////////////////////////////////////////
31 
32 
33 #include <ROOT/RConfig.hxx> // for R__DEPRECATED
34 #include <DllImport.h> // for R__EXTERN
35 #include "RtypesCore.h"
36 
37 #include <cstdarg>
38 #include <functional>
39 
40 
41 class TVirtualMutex;
42 R__EXTERN TVirtualMutex *gErrorMutex R__DEPRECATED(6,26, "ROOT stopped exporting gErrorMutex.");
43 
44 const Int_t kUnset = -1;
45 const Int_t kPrint = 0;
46 const Int_t kInfo = 1000;
47 const Int_t kWarning = 2000;
48 const Int_t kError = 3000;
49 const Int_t kBreak = 4000;
50 const Int_t kSysError = 5000;
51 const Int_t kFatal = 6000;
52 
53 
54 // TROOT sets the error ignore level handler, the system error message handler, and the error abort handler on
55 // construction such that the "Root.ErrorIgnoreLevel" environment variable is used for the ignore level
56 // and gSystem is used to generate a stack trace on abort.
57 namespace ROOT {
58 namespace Internal {
59 
60 /// Retrieves the error string associated with the last system error.
62 
64 /// Returns the previous system error message handler
66 
67 void MinimalErrorHandler(int level, Bool_t abort, const char *location, const char *msg);
68 
69 } // namespace Internal
70 } // namespace ROOT
71 
72 typedef void (*ErrorHandlerFunc_t)(int level, Bool_t abort, const char *location,
73  const char *msg);
74 
75 extern "C" void ErrorHandler(int level, const char *location, const char *fmt, std::va_list va);
76 
77 extern void DefaultErrorHandler(int level, Bool_t abort, const char *location, const char *msg);
78 
81 
82 extern void Info(const char *location, const char *msgfmt, ...)
83 #if defined(__GNUC__) && !defined(__CINT__)
84 __attribute__((format(printf, 2, 3)))
85 #endif
86 ;
87 extern void Warning(const char *location, const char *msgfmt, ...)
88 #if defined(__GNUC__) && !defined(__CINT__)
89 __attribute__((format(printf, 2, 3)))
90 #endif
91 ;
92 extern void Error(const char *location, const char *msgfmt, ...)
93 #if defined(__GNUC__) && !defined(__CINT__)
94 __attribute__((format(printf, 2, 3)))
95 #endif
96 ;
97 extern void Break(const char *location, const char *msgfmt, ...)
98 #if defined(__GNUC__) && !defined(__CINT__)
99 __attribute__((format(printf, 2, 3)))
100 #endif
101 ;
102 extern void SysError(const char *location, const char *msgfmt, ...)
103 #if defined(__GNUC__) && !defined(__CINT__)
104 __attribute__((format(printf, 2, 3)))
105 #endif
106 ;
107 extern void Fatal(const char *location, const char *msgfmt, ...)
108 #if defined(__GNUC__) && !defined(__CINT__)
109 __attribute__((format(printf, 2, 3)))
110 #endif
111 ;
112 
113 extern void AbstractMethod(const char *method);
114 extern void MayNotUse(const char *method);
115 extern void Obsolete(const char *function, const char *asOfVers, const char *removedFromVers);
116 
117 R__EXTERN const char *kAssertMsg;
118 R__EXTERN const char *kCheckMsg;
119 
120 #define R__ASSERT(e) \
121  do { \
122  if (!(e)) ::Fatal("", kAssertMsg, _QUOTE_(e), __LINE__, __FILE__); \
123  } while (false)
124 #define R__CHECK(e) \
125  do { \
126  if (!(e)) ::Warning("", kCheckMsg, _QUOTE_(e), __LINE__, __FILE__); \
127  } while (false)
128 
132 
133 #endif
kSysError
const Int_t kSysError
Definition: TError.h:50
MayNotUse
void MayNotUse(const char *method)
This function can be used in classes that should override a certain function, but in the inherited cl...
Definition: TError.cxx:170
kFatal
const Int_t kFatal
Definition: TError.h:51
gPrintViaErrorHandler
R__EXTERN Bool_t gPrintViaErrorHandler
Definition: TError.h:131
Warning
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Definition: TError.cxx:231
ErrorHandlerFunc_t
void(* ErrorHandlerFunc_t)(int level, Bool_t abort, const char *location, const char *msg)
Definition: TError.h:72
ROOT::Internal::ErrorSystemMsgHandlerFunc_t
std::function< const char *()> ErrorSystemMsgHandlerFunc_t
Retrieves the error string associated with the last system error.
Definition: TError.h:61
kWarning
const Int_t kWarning
Definition: TError.h:47
GetErrorHandler
ErrorHandlerFunc_t GetErrorHandler()
Returns the current error handler function.
Definition: TError.cxx:102
kError
const Int_t kError
Definition: TError.h:48
Int_t
int Int_t
Definition: RtypesCore.h:45
gErrorMutex
TVirtualMutex * gErrorMutex
Error handling routines.
Definition: TError.cxx:32
TVirtualMutex
Definition: TVirtualMutex.h:32
RConfig.hxx
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
h
#define h(i)
Definition: RSha256.hxx:124
kAssertMsg
const R__EXTERN char * kAssertMsg
Definition: TError.h:117
Fatal
void Fatal(const char *location, const char *msgfmt,...)
Use this function in case of a fatal error. It will abort the program.
Definition: TError.cxx:245
ROOT::R::function
void function(const Char_t *name_, T fun, const Char_t *docstring=0)
Definition: RExports.h:151
ErrorHandler
void ErrorHandler(int level, const char *location, const char *fmt, std::va_list va)
General error handler function. It calls the user set error handler.
Definition: TError.cxx:111
Break
void Break(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition: TError.cxx:209
Obsolete
void Obsolete(const char *function, const char *asOfVers, const char *removedFromVers)
Use this function to declare a function obsolete.
Definition: TError.cxx:179
gErrorAbortLevel
R__EXTERN Int_t gErrorAbortLevel
Definition: TError.h:130
void
typedef void((*Func_t)())
DefaultErrorHandler
void DefaultErrorHandler(int level, Bool_t abort, const char *location, const char *msg)
The default error handler function.
Definition: TErrorDefaultHandler.cxx:101
SetErrorHandler
ErrorHandlerFunc_t SetErrorHandler(ErrorHandlerFunc_t newhandler)
Set an errorhandler function. Returns the old handler.
Definition: TError.cxx:92
gErrorIgnoreLevel
R__EXTERN Int_t gErrorIgnoreLevel
Definition: TError.h:129
RtypesCore.h
SysError
void SysError(const char *location, const char *msgfmt,...)
Use this function in case a system (OS or GUI) related error occurred.
Definition: TError.cxx:198
Info
void Info(const char *location, const char *msgfmt,...)
Use this function for informational messages.
Definition: TError.cxx:220
kCheckMsg
const R__EXTERN char * kCheckMsg
Definition: TError.h:118
AbstractMethod
void AbstractMethod(const char *method)
This function can be used in abstract base classes in case one does not want to make the class a "rea...
Definition: TError.cxx:161
kBreak
const Int_t kBreak
Definition: TError.h:49
ROOT::Internal::SetErrorSystemMsgHandler
ErrorSystemMsgHandlerFunc_t SetErrorSystemMsgHandler(ErrorSystemMsgHandlerFunc_t h)
Returns the previous system error message handler.
Definition: TError.cxx:59
R__EXTERN
#define R__EXTERN
Definition: DllImport.h:27
kInfo
const Int_t kInfo
Definition: TError.h:46
ROOT::Internal::GetErrorSystemMsgHandler
ErrorSystemMsgHandlerFunc_t GetErrorSystemMsgHandler()
Definition: TError.cxx:54
R__DEPRECATED
R__EXTERN TVirtualMutex *gErrorMutex R__DEPRECATED(6, 26, "ROOT stopped exporting gErrorMutex.")
ROOT
VSD Structures.
Definition: StringConv.hxx:21
kUnset
const Int_t kUnset
Definition: TError.h:44
ROOT::Internal::MinimalErrorHandler
void MinimalErrorHandler(int level, Bool_t abort, const char *location, const char *msg)
A very simple error handler that is usually replaced by the TROOT default error handler.
Definition: TError.cxx:69
DllImport.h
kPrint
const Int_t kPrint
Definition: TError.h:45
Error
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition: TError.cxx:187