EtcPal  0.4.1
ETC Platform Abstraction Layer (EtcPal)
View other versions:
Error Class Reference

Overview

A wrapper class for the EtcPal error type.

Provides C++ syntactic sugar on top of etcpal_error_t codes. A Error can be created from an etcpal_error_t, and contains the code and a string representation. If the Error contains kEtcPalErrOk, it will evaluate to true in expressions (and IsOk() will return true). Otherwise, the Error evaluates to false.

The human-readable string associated with the Error can be retrieved with ToString() and ToCString(); this will be the same string available from etcpal_strerror() for the given error code.

Example with an "OK" error code:

auto result = etcpal::Error(kEtcPalErrOk); // or etcpal::Error::Ok()
if (result)
{
// This block will be entered...
}
A wrapper class for the EtcPal error type.
Definition: error.h:94
@ kEtcPalErrOk
The call was successful, no error occurred.
Definition: error.h:51

Example with a non-"OK" error code:

if (result)
{
// This block will not be entered
}
else
{
// This block will be entered
printf("Error: '%s'", result.ToCString());
// Or
std::cout << "Error: '" << result.ToString() << "'\n";
// Prints "Error: 'Out of memory'"
}
@ kEtcPalErrNoMem
A dynamic memory allocation failed, or there is no space left in a statically allocated array.
Definition: error.h:56

Error is often used as the return type for functions; it has an implicit constructor from etcpal_error_t to simplify return statements:

etcpal::Error DoSomething()
{
// ... After we did something successfully...
return kEtcPalErrOk;
}

Public Member Functions

constexpr Error (etcpal_error_t code) noexcept
 Construct a Error from an error code.
 
Erroroperator= (etcpal_error_t code) noexcept
 Assign an error code to this Error.
 
constexpr bool IsOk () const noexcept
 Whether this Error contains the code kEtcPalErrOk. More...
 
constexpr etcpal_error_t code () const noexcept
 Get the underlying code from a Error.
 
std::string ToString () const
 Get a descriptive string for this Error as a std::string.
 
const char * ToCString () const noexcept
 Get a descriptive string for this Error as a C string.
 
constexpr operator bool () const noexcept
 Evaluate the Error inline - evaluates true if the Error is kEtcPalErrOk, false otherwise.
 

Static Public Member Functions

static constexpr Error Ok () noexcept
 Construct an Error containing kEtcPalErrOk.
 

Member Function Documentation

◆ IsOk()

constexpr bool IsOk ( ) const
constexprnoexcept

Whether this Error contains the code kEtcPalErrOk.

kEtcPalErrOk is the only etcpal_error_t code that does not indicate an error.


The documentation for this class was generated from the following file: