Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-12-15 10:29:36

0001 // @(#)root/base:$Id$
0002 // Author: Fons Rademakers   29/07/95
0003 
0004 /*************************************************************************
0005  * Copyright (C) 1995-2000, Rene Brun and Fons Rademakers.               *
0006  * All rights reserved.                                                  *
0007  *                                                                       *
0008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0010  *************************************************************************/
0011 
0012 #ifndef ROOT_TError
0013 #define ROOT_TError
0014 
0015 
0016 //////////////////////////////////////////////////////////////////////////
0017 //                                                                      //
0018 // Error handling routines.                                             //
0019 //                                                                      //
0020 // This file defines a number of global error handling routines:        //
0021 // Warning(), Error(), SysError() and Fatal(). They all take a          //
0022 // location string (where the error happened) and a printf style format //
0023 // string plus vararg's. In the end these functions call an             //
0024 // errorhanlder function. Initially, a minimal, non thread-safe handler //
0025 // is installed that is supposed to be replaced by the                  //
0026 // DefaultErrorHandler(), which needs to be implemented and installed   //
0027 // by the user of TError.  Normally, the default error handler is set   //
0028 // during gROOT initialization.                                         //
0029 //                                                                      //
0030 //////////////////////////////////////////////////////////////////////////
0031 
0032 
0033 #include <DllImport.h> // for R__EXTERN
0034 #include "RtypesCore.h"
0035 #include <ROOT/RConfig.hxx>
0036 
0037 #include <cstdarg>
0038 #include <functional>
0039 
0040 
0041 class TVirtualMutex;
0042 
0043 constexpr Int_t kUnset    =  -1;
0044 constexpr Int_t kPrint    =   0;
0045 constexpr Int_t kInfo     =   1000;
0046 constexpr Int_t kWarning  =   2000;
0047 constexpr Int_t kError    =   3000;
0048 constexpr Int_t kBreak    =   4000;
0049 constexpr Int_t kSysError =   5000;
0050 constexpr Int_t kFatal    =   6000;
0051 
0052 
0053 // TROOT sets the error ignore level handler, the system error message handler, and the error abort handler on
0054 // construction such that the "Root.ErrorIgnoreLevel" environment variable is used for the ignore level
0055 // and gSystem is used to generate a stack trace on abort.
0056 namespace ROOT {
0057 namespace Internal {
0058 
0059 /// Retrieves the error string associated with the last system error.
0060 using ErrorSystemMsgHandlerFunc_t = std::function<const char *()>;
0061 
0062 ErrorSystemMsgHandlerFunc_t GetErrorSystemMsgHandler();
0063 /// Returns the previous system error message handler
0064 ErrorSystemMsgHandlerFunc_t SetErrorSystemMsgHandler(ErrorSystemMsgHandlerFunc_t h);
0065 
0066 void MinimalErrorHandler(int level, Bool_t abort, const char *location, const char *msg);
0067 
0068 } // namespace Internal
0069 } // namespace ROOT
0070 
0071 typedef void (*ErrorHandlerFunc_t)(int level, Bool_t abort, const char *location,
0072               const char *msg);
0073 
0074 extern "C" void ErrorHandler(int level, const char *location, const char *fmt, std::va_list va);
0075 
0076 extern void DefaultErrorHandler(int level, Bool_t abort, const char *location, const char *msg);
0077 
0078 extern ErrorHandlerFunc_t SetErrorHandler(ErrorHandlerFunc_t newhandler);
0079 extern ErrorHandlerFunc_t GetErrorHandler();
0080 
0081 extern void Info(const char *location, const char *msgfmt, ...)
0082 #if defined(__GNUC__)
0083 __attribute__((format(printf, 2, 3)))
0084 #endif
0085 ;
0086 extern void Warning(const char *location, const char *msgfmt, ...)
0087 #if defined(__GNUC__)
0088 __attribute__((format(printf, 2, 3)))
0089 #endif
0090 ;
0091 extern void Error(const char *location, const char *msgfmt, ...)
0092 #if defined(__GNUC__)
0093 __attribute__((format(printf, 2, 3)))
0094 #endif
0095 ;
0096 extern void Break(const char *location, const char *msgfmt, ...)
0097 #if defined(__GNUC__)
0098 __attribute__((format(printf, 2, 3)))
0099 #endif
0100 ;
0101 extern void SysError(const char *location, const char *msgfmt, ...)
0102 #if defined(__GNUC__)
0103 __attribute__((format(printf, 2, 3)))
0104 #endif
0105 ;
0106 extern void Fatal(const char *location, const char *msgfmt, ...)
0107 #if defined(__GNUC__)
0108 __attribute__((format(printf, 2, 3)))
0109 #endif
0110 ;
0111 
0112 extern void AbstractMethod(const char *method);
0113 extern void MayNotUse(const char *method);
0114 extern void Obsolete(const char *function, const char *asOfVers, const char *removedFromVers);
0115 
0116 R__EXTERN const char *kAssertMsg;
0117 R__EXTERN const char *kCheckMsg;
0118 
0119 /*! Checks condition `e` and reports a fatal error if it's false.
0120  * \warning
0121  *   - this check is NOT stripped in release mode, so it should not be used for hot paths.
0122  *     For those cases, prefer a regular `assert()`;
0123  *   - depending on `gErrorIgnoreLevel`, this might not terminate the program, \see ::Fatal.
0124  */
0125 #define R__ASSERT(e)                                              \
0126    do {                                                           \
0127       if (R__unlikely(!(e)))                                      \
0128          ::Fatal("", kAssertMsg, _QUOTE_(e), __LINE__, __FILE__); \
0129    } while (false)
0130 
0131 /*! Checks condition `e` and reports a warning message if it's false.
0132  * \warning this check is NOT stripped in release mode, so it should not be used for hot paths.
0133  */
0134 #define R__CHECK(e)                                                \
0135    do {                                                            \
0136       if (R__unlikely(!(e)))                                       \
0137          ::Warning("", kCheckMsg, _QUOTE_(e), __LINE__, __FILE__); \
0138    } while (false)
0139 
0140 R__EXTERN Int_t  gErrorIgnoreLevel;    ///< errors with level below this value will be ignored. Default is `kUnset`.
0141 R__EXTERN Int_t  gErrorAbortLevel;     ///< non-ignored errors with level equal or above this value will call abort(). Default is `kSysError+1`.
0142 R__EXTERN Bool_t gPrintViaErrorHandler;///< If true, ROOT's `Printf` will print via the currently active ROOT error handler; if false (default), it will use the standard `printf`.
0143 
0144 #endif