Skip to content

EntropyEngine::Networking::Result

Result type for operations that may fail. More…

#include <ErrorCodes.h>

Name
T &valueOrThrow()
Get the value or throw on error.
boolsuccess() const
Check if operation succeeded.
Result< T >ok(T val)
Create a successful result.
boolfailed() const
Check if operation failed.
Result< T >err(NetworkError err, std::string message ="")
Create a failed result.
Name
Tvalue
Result value (valid only if error == None).
std::stringerrorMessage
Optional detailed error message.
NetworkErrorerror
Error code.
template <typename T >
struct EntropyEngine::Networking::Result;

Result type for operations that may fail.

Encapsulates a value and an error code. Check success() before accessing value.

auto result = someOperation();
if (result.success()) {
useValue(result.value);
} else {
handleError(result.error);
}
inline T & valueOrThrow()

Get the value or throw on error.

Exceptions:

  • std::runtime_error if operation failed

Return: The contained value

inline bool success() const

Check if operation succeeded.

Return: true if no error occurred

static inline Result< T > ok(
T val
)

Create a successful result.

Parameters:

  • val The result value

Return: Result with no error

inline bool failed() const

Check if operation failed.

Return: true if an error occurred

static inline Result< T > err(
NetworkError err,
std::string message =""
)

Create a failed result.

Parameters:

  • err The error code
  • message Optional error message

Return: Result with error

T value;

Result value (valid only if error == None).

std::string errorMessage;

Optional detailed error message.

NetworkError error;

Error code.


Updated on 2026-01-26 at 17:14:35 -0500