template<typename T>
class ROOT::RResult< T >
The class is used as a return type for operations that can fail; wraps a value of type T or an RError.
The RResult<T> class and their related classes are used for call chains that can throw exceptions, such as I/O code paths. Throwing of the exception is deferred to allow for if (result)
style error checking where it makes sense. If an RResult in error state leaves the scope unchecked, it will throw.
A function returning an RResult might look like this:
{
int rv = syscall(...);
if (rv == -1)
return R__FAIL(
"user-facing error message");
if (rv == kShortcut)
return 42;
}
#define R__FORWARD_RESULT(res)
Short-hand to return an RResult<T> value from a subroutine to the calling stack frame.
#define R__FAIL(msg)
Short-hand to return an RResult<T> in an error state; the RError is implicitly converted into RResult...
The class is used as a return type for operations that can fail; wraps a value of type T or an RError...
Code using MyIOFunc might look like this:
auto result = MyIOOperation();
}
...
}
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 result
Note that RResult<void> can be used for a function without return value, like this
{
if (failure)
return R__FAIL(
"user-facing error messge");
}
RResult<T>::Unwrap() can be used as a short hand for "give me the wrapped value or, in case of an error, throw". For instance:
int value = FuncThatReturnsRResultOfInt().Unwrap();
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
There is no implict operator that converts RResult<T> to T. This is intentional to make it clear in the calling code where an exception may be thrown.
Definition at line 197 of file RError.hxx.
If the operation was successful, returns the inner type by value.
For move-only types, Unwrap can only be called once, as it yields ownership of the inner value to the caller using std::move, potentially leaving the RResult in an unspecified state.
If there was an error, Unwrap() instead throws an exception.
Definition at line 252 of file RError.hxx.