Contexts and Errors

class Context

Container for UNIT’s state. This type cannot be implicitly copied.

This is a wrapper around UNIT_Context.

Context()

Initialize a context. This calls UNIT_Context_Init() internally.

Quirk

On failure, this raises a std::runtime_exception instead of a unit::error.

UNIT_Context *raw()

Get the raw UNIT_Context that this class is wrapping.

Context(const Context&) = delete
Context &operator=(const Context&) = delete

These prevent implicit copying of this type.

enum class ErrorCode

Scoped wrapper around UNIT_ErrorCode. Values in this enum are guaranteed to be equivalent to their C counterpart (and thus statically casting this enum to UNIT_ErrorCode is safe).

C++ Enum

C Enum

enumerator NONE

UNIT_ERROR_NONE

enumerator NO_MEMORY

UNIT_ERROR_NO_MEMORY

enumerator INVALID_USAGE

UNIT_ERROR_INVALID_USAGE

enumerator OS_FAILURE

UNIT_ERROR_OS_FAILURE

enumerator UNSUPPORTED_PLATFORM

UNIT_ERROR_UNSUPPORTED_PLATFORM

class error : public std::runtime_exception

Wrapper around UNIT’s error API as a C++ exception. Functions that return UNIT_Status in UNIT’s C API will raise this exception from their C++ counterpart.

error(UNIT_Context *ctx)
Parameters:

ctx – The raw UNIT_Context in which the error originated.

ErrorCode code() const

Get the error code.