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
51{
52 if (R__unlikely(fError && !fIsChecked)) {
53 // Prevent from throwing if the object is deconstructed in the course of stack unwinding for another exception
54#if __cplusplus >= 201703L
55 if (std::uncaught_exceptions() == 0)
56#else
57 if (!std::uncaught_exception())
58#endif
59 {
60 throw RException(*fError);
61 } else {
62 R__LOG_WARNING() << "unhandled RResult exception during stack unwinding";
63 }
64 }
65}
66
68{
69 throw ROOT::Experimental::RException(*fError);
70}
#define R__unlikely(expr)
Definition RConfig.hxx:594
#define R__LOG_WARNING(...)
Definition RLogger.hxx:363
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
void Throw()
Throws an RException with fError.
Definition RError.cxx:67
~RResultBase() noexcept(false)
Definition RError.cxx:50