Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RError.cxx
Go to the documentation of this file.
1/// \file RError.cxx
2/// \ingroup Base ROOT7
3/// \author Jakob Blomer <jblomer@cern.ch>
4/// \date 2019-12-11
5/// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
6/// is welcome!
7
8/*************************************************************************
9 * Copyright (C) 1995-2020, Rene Brun and Fons Rademakers. *
10 * All rights reserved. *
11 * *
12 * For the licensing terms see $ROOTSYS/LICENSE. *
13 * For the list of contributors see $ROOTSYS/README/CREDITS. *
14 *************************************************************************/
15
16#include <ROOT/RConfig.hxx> // for R__[un]likely
17#include <ROOT/RError.hxx>
18#include <ROOT/RLogger.hxx> // for R__LOG_WARNING
19
20#include <exception>
21#include <string>
22#include <utility>
23
24
26{
27 auto report = fMessage + "\nAt:\n";
28 for (const auto &loc : fStackTrace) {
29 report += " " + std::string(loc.fFunction) + " [" + std::string(loc.fSourceFile) + ":" +
30 std::to_string(loc.fSourceLine) + "]\n";
31 }
32 return report;
33}
34
36 const std::string &message, RLocation &&sourceLocation)
37 : fMessage(message)
38
39{
40 // Avoid frequent reallocations as we move up the call stack
41 fStackTrace.reserve(32);
42 AddFrame(std::move(sourceLocation));
43}
44
46{
47 fStackTrace.emplace_back(sourceLocation);
48}
49
50
52{
53 if (R__unlikely(fError && !fIsChecked)) {
54 // Prevent from throwing if the object is deconstructed in the course of stack unwinding for another exception
55#if __cplusplus >= 201703L
56 if (std::uncaught_exceptions() == 0)
57#else
58 if (!std::uncaught_exception())
59#endif
60 {
61 throw RException(*fError);
62 } else {
63 R__LOG_WARNING() << "unhandled RResult exception during stack unwinding";
64 }
65 }
66}
67
68
70{
71 throw ROOT::Experimental::RException(*fError);
72}
#define R__unlikely(expr)
Definition RConfig.hxx:601
#define R__LOG_WARNING(...)
Definition RLogger.hxx:363
void Throw()
Throws an RException with fError.
Definition RError.cxx:69
std::string fMessage
User-facing error message.
Definition RError.hxx:55
void AddFrame(RLocation &&sourceLocation)
Used by R__FORWARD_RESULT.
Definition RError.cxx:45
std::vector< RLocation > fStackTrace
The location of the error related to fMessage plus upper frames if the error is forwarded through the...
Definition RError.hxx:57
RError(const std::string &message, RLocation &&sourceLocation)
Used by R__FAIL.
Definition RError.cxx:35
std::string GetReport() const
Format a dignostics report, e.g. for an exception message.
Definition RError.cxx:25
Base class for all ROOT issued exceptions.
Definition RError.hxx:78