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