Skip to main content

nebula::core::Result

ara::core::Result acts as a “wrapper type” that connects the exception-less API approach using ara::core::ErrorCode with C++ exceptions. As there is a direct mapping between ara::core::ErrorCode and a domain-specific exception type, nebula::core::Result allows to “transform” its embedded ara::core::ErrorCode into the appropriate exception type, by calling ara::core::Result::ValueOrThrow.

// Custom Object
struct EventData {
// Member definitions
};

enum class CustomErrors {
// Error definitions
...
CreationFail = 100;
};
...

nebula::core::Result<EventData, CustomErrors> CreateEventData() {
// Try to create EventData;

if(creationFlag) { // creation succeeded
return eventDataObj;
}
return CustomErrors::CreationFail;
}

// Any function using the CreateEventData method
{
auto ret = CreateEventData();
if(ret.HasValue()) {
// Success case, ie; CreateEventData() succeeded.
auto eventData = ret.Value();
...
} else {
// Failure case
auto err = ret.Error();
// handle error situation
}
}
  • Parameters
    • T the type of value
    • E the type of error

class nebula::core::Result

The nebula::core::Result is a customized implementation of ara::core::Result. The ara::core::Result type follows the ValueOrError concept. It either contains a value (of type ValueType), or an error (of type ErrorType). Both ValueType and ErrorType are template parameters of ara::core::Result.

Members

public inline Result(T && t)

Construct a new Result from the specified value (given as rvalue).

  • Parameters
    • t the value to put into the Result

public inline Result(E const & e)

Construct a new Result from the specified error (given as lvalue).

  • Parameters
    • e the error to put into the Result

public inline Result(E && e)

Construct a new Result from the specified error (given as rvalue).

  • Parameters
    • e the error to put into the Result

public inline bool HasValue()

Check whether *this contains a value.

  • Returns true if *this contains a value

  • Returns false other cases

public inline T & Value()

Access the contained value. The behavior of this function is undefined if *this does not contain a value.

  • Returns T& a const reference to the contained value

public inline E & Error()

Access the contained error. The behavior of this function is undefined if *this does not contain an error.

  • Returns E& a const reference to the contained error

public inline const T & ValueOrThrow() const

Return the contained value or throw an exception. This function does not participate in overload resolution when the compiler tool chain does not support C++ exceptions.

  • Returns const T& a const reference to the contained value

typedef valueType

Type alias for the type T of values .

typedef errorType

Type alias for the type E of errors .

public template<>
inline static Result FromValue(Args &&... args)

Build a new Result from a value that is constructed in-place from the given arguments.

This function shall not participate in overload resolution unless: std::is_constructible<T,Args&&...>::value is true, and the first type of the expanded parameter pack is not T, and the first type of the expanded parameter pack is not a specialization of Result

  • Parameters

    • Args the types of arguments given to this function
  • Parameters

    • args the arguments used for constructing the value
  • Returns Result a Result that contains a value

public inline static Result FromValue(T const & t)

Construct a new Result from the specified value (given as lvalue).

  • Parameters

    • t the value to put into the Result
  • Returns Result Constructed Result object with the value

public template<>
inline static Result FromError(Args &&... args)

Build a new Result from an error that is constructed in-place from the given arguments.

This function shall not participate in overload resolution unless: std::is_constructible<E,Args&&...>::value is true, and the first type of the expanded parameter pack is not E, and the first type of the expanded parameter pack is not a specialization of Result

  • Parameters

    • Args the types of arguments given to this function
  • Parameters

    • args the arguments used for constructing the error
  • Returns Result a Result that contains an error

public inline static Result FromError(E err)

Build a new Result from the specified error (given as lvalue).

  • Parameters

    • err the error to put into the Result
  • Returns Result a Result that contains the error err