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
6/*************************************************************************
7 * Copyright (C) 1995-2020, Rene Brun and Fons Rademakers. *
8 * All rights reserved. *
9 * *
10 * For the licensing terms see $ROOTSYS/LICENSE. *
11 * For the list of contributors see $ROOTSYS/README/CREDITS. *
12 *************************************************************************/
13
14#include <ROOT/RConfig.hxx> // for R__[un]likely
15#include <ROOT/RError.hxx>
16#include <ROOT/RLogger.hxx> // for R__LOG_WARNING
17
18#include <exception>
19#include <string>
20#include <utility>
21
22std::string ROOT::RError::GetReport() const
23{
24 auto report = fMessage + "\nAt:\n";
25 for (const auto &loc : fStackTrace) {
26 report += " " + std::string(loc.fFunction) + " [" + std::string(loc.fSourceFile) + ":" +
27 std::to_string(loc.fSourceLine) + "]\n";
28 }
29 return report;
30}
31
32ROOT::RError::RError(std::string_view message, RLocation &&sourceLocation) : fMessage(message)
33
34{
35 // Avoid frequent reallocations as we move up the call stack
36 fStackTrace.reserve(32);
37 AddFrame(std::move(sourceLocation));
38}
39
40void ROOT::RError::AddFrame(RLocation &&sourceLocation)
41{
42 fStackTrace.emplace_back(sourceLocation);
43}
44
46{
47 if (R__unlikely(fError && !fIsChecked)) {
48 // Prevent from throwing if the object is deconstructed in the course of stack unwinding for another exception
49#if __cplusplus >= 201703L
50 if (std::uncaught_exceptions() == 0)
51#else
52 if (!std::uncaught_exception())
53#endif
54 {
55 throw RException(*fError);
56 } else {
57 R__LOG_WARNING() << "unhandled RResult exception during stack unwinding";
58 }
59 }
60}
61
63{
64 throw ROOT::RException(*fError);
65}
#define R__unlikely(expr)
Definition RConfig.hxx:602
#define R__LOG_WARNING(...)
Definition RLogger.hxx:363
RError(std::string_view message, RLocation &&sourceLocation)
Used by R__FAIL.
Definition RError.cxx:32
void AddFrame(RLocation &&sourceLocation)
Used by R__FORWARD_RESULT.
Definition RError.cxx:40
std::string fMessage
User-facing error message.
Definition RError.hxx:56
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:58
std::string GetReport() const
Format a dignostics report, e.g. for an exception message.
Definition RError.cxx:22
Base class for all ROOT issued exceptions.
Definition RError.hxx:79
~RResultBase() noexcept(false)
Definition RError.cxx:45
void Throw()
Throws an RException with fError.
Definition RError.cxx:62