Exceptions#

Defined in namespace mem

import strong_ptr;

class exception : public std::exception#

Base exception class for all hal related exceptions.

Subclassed by v1::nullptr_access, v1::out_of_range

Public Functions

inline constexpr std::errc error_code() const#

Convert this exception to the closest C++ error code.

Main Use Case: Translation from C++ exceptions to C error codes

Lets consider a situation when a C++ program must interface with C code or code that uses a C API to operate. Normally C++ code calls C code, but if C++ code is given to a C API like a callback and that C api expects an error code back for its own error handling purposes, this class function provides that error code. Simply catch the mem::exception, and return an error code. Perform any other recovery or handling required to make the system perform as expected.

Other use cases:

  1. Logging

Log the error code value (or the stringified version) of this exception to alert developers of the kind of underlying exception that was thrown.

  1. Recovery

This can be used for recovery, but it is HIGHLY RECOMMENDED to use the derived classes in their own catch blocks to recover from a specific error rather than using the base class and extracting its error code.

Returns:

std::errc - error code represented by the exception

out_of_range#

struct out_of_range : public v1::exception#

Raised when an API attempts to access elements outside of a container or resource.

struct info#

nullptr_access#

struct nullptr_access : public v1::exception#

Raised when an API attempts to access the contents of an empty optional_ptr.