Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 <DllImport.h> // for R__EXTERN
34#include "RtypesCore.h"
35#include <ROOT/RConfig.hxx>
36
37#include <cstdarg>
38#include <functional>
39
40
41class TVirtualMutex;
42
43constexpr Int_t kUnset = -1;
44constexpr Int_t kPrint = 0;
45constexpr Int_t kInfo = 1000;
46constexpr Int_t kWarning = 2000;
47constexpr Int_t kError = 3000;
48constexpr Int_t kBreak = 4000;
49constexpr Int_t kSysError = 5000;
50constexpr Int_t kFatal = 6000;
51
52
53// TROOT sets the error ignore level handler, the system error message handler, and the error abort handler on
54// construction such that the "Root.ErrorIgnoreLevel" environment variable is used for the ignore level
55// and gSystem is used to generate a stack trace on abort.
56namespace ROOT {
57namespace Internal {
58
59/// Retrieves the error string associated with the last system error.
60using ErrorSystemMsgHandlerFunc_t = std::function<const char *()>;
61
63/// Returns the previous system error message handler
65
66void MinimalErrorHandler(int level, Bool_t abort, const char *location, const char *msg);
67
68} // namespace Internal
69} // namespace ROOT
70
71typedef void (*ErrorHandlerFunc_t)(int level, Bool_t abort, const char *location,
72 const char *msg);
73
74extern "C" void ErrorHandler(int level, const char *location, const char *fmt, std::va_list va);
75
76extern void DefaultErrorHandler(int level, Bool_t abort, const char *location, const char *msg);
77
80
81extern void Info(const char *location, const char *msgfmt, ...)
82#if defined(__GNUC__)
83__attribute__((format(printf, 2, 3)))
84#endif
85;
86extern void Warning(const char *location, const char *msgfmt, ...)
87#if defined(__GNUC__)
88__attribute__((format(printf, 2, 3)))
89#endif
90;
91extern void Error(const char *location, const char *msgfmt, ...)
92#if defined(__GNUC__)
93__attribute__((format(printf, 2, 3)))
94#endif
95;
96extern void Break(const char *location, const char *msgfmt, ...)
97#if defined(__GNUC__)
98__attribute__((format(printf, 2, 3)))
99#endif
100;
101extern void SysError(const char *location, const char *msgfmt, ...)
102#if defined(__GNUC__)
103__attribute__((format(printf, 2, 3)))
104#endif
105;
106extern void Fatal(const char *location, const char *msgfmt, ...)
107#if defined(__GNUC__)
108__attribute__((format(printf, 2, 3)))
109#endif
110;
111
112extern void AbstractMethod(const char *method);
113extern void MayNotUse(const char *method);
114extern void Obsolete(const char *function, const char *asOfVers, const char *removedFromVers);
115
116R__EXTERN const char *kAssertMsg;
117R__EXTERN const char *kCheckMsg;
118
119/*! Checks condition `e` and reports a fatal error if it's false.
120 * \warning
121 * - this check is NOT stripped in release mode, so it should not be used for hot paths.
122 * For those cases, prefer a regular `assert()`;
123 * - depending on `gErrorIgnoreLevel`, this might not terminate the program, \see ::Fatal.
124 */
125#define R__ASSERT(e) \
126 do { \
127 if (R__unlikely(!(e))) \
128 ::Fatal("", kAssertMsg, _QUOTE_(e), __LINE__, __FILE__); \
129 } while (false)
130
131/*! Checks condition `e` and reports a warning message if it's false.
132 * \warning this check is NOT stripped in release mode, so it should not be used for hot paths.
133 */
134#define R__CHECK(e) \
135 do { \
136 if (R__unlikely(!(e))) \
137 ::Warning("", kCheckMsg, _QUOTE_(e), __LINE__, __FILE__); \
138 } while (false)
139
143
144#endif
#define R__EXTERN
Definition DllImport.h:26
#define h(i)
Definition RSha256.hxx:106
bool Bool_t
Definition RtypesCore.h:63
int Int_t
Definition RtypesCore.h:45
void DefaultErrorHandler(int level, Bool_t abort, const char *location, const char *msg)
The default error handler function.
Int_t gErrorAbortLevel
Definition TError.cxx:32
const char * kAssertMsg
Definition TError.cxx:35
constexpr Int_t kError
Definition TError.h:47
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:109
ErrorHandlerFunc_t GetErrorHandler()
Returns the current error handler function.
Definition TError.cxx:100
void Info(const char *location, const char *msgfmt,...)
Use this function for informational messages.
Definition TError.cxx:218
constexpr Int_t kFatal
Definition TError.h:50
constexpr Int_t kWarning
Definition TError.h:46
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:185
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:159
void SysError(const char *location, const char *msgfmt,...)
Use this function in case a system (OS or GUI) related error occurred.
Definition TError.cxx:196
void(* ErrorHandlerFunc_t)(int level, Bool_t abort, const char *location, const char *msg)
Definition TError.h:71
constexpr Int_t kBreak
Definition TError.h:48
void Break(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Definition TError.cxx:207
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:168
constexpr Int_t kPrint
Definition TError.h:44
constexpr Int_t kInfo
Definition TError.h:45
Int_t gErrorIgnoreLevel
Error handling routines.
Definition TError.cxx:31
constexpr Int_t kSysError
Definition TError.h:49
const char * kCheckMsg
Definition TError.cxx:36
void Obsolete(const char *function, const char *asOfVers, const char *removedFromVers)
Use this function to declare a function obsolete.
Definition TError.cxx:177
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
Definition TError.cxx:229
ErrorHandlerFunc_t SetErrorHandler(ErrorHandlerFunc_t newhandler)
Set an errorhandler function. Returns the old handler.
Definition TError.cxx:90
constexpr Int_t kUnset
Definition TError.h:43
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:244
Bool_t gPrintViaErrorHandler
Definition TError.cxx:33
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t format
This class implements a mutex interface.
std::function< const char *()> ErrorSystemMsgHandlerFunc_t
Retrieves the error string associated with the last system error.
Definition TError.h:60
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:67
ErrorSystemMsgHandlerFunc_t SetErrorSystemMsgHandler(ErrorSystemMsgHandlerFunc_t h)
Returns the previous system error message handler.
Definition TError.cxx:56
ErrorSystemMsgHandlerFunc_t GetErrorSystemMsgHandler()
Definition TError.cxx:51
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...