|
nros C++ API
Lightweight ROS 2 client for embedded real-time systems (C++ headers)
|
nros::Result, nros::ErrorCode, and the NROS_TRY macro.
More...
#include <cstdint>#include <utility>

Go to the source code of this file.
Classes | |
| class | nros::Expected< T > |
| class | nros::Result |
Namespaces | |
| namespace | nros |
Macros | |
| #define | NROS_CHECK(expr) |
| #define | NROS_TRY(expr) |
| #define | NROS_TRY_LOG(file, line, expr, ret) ((void)(file), (void)(line), (void)(expr), (void)(ret)) |
| #define | NROS_TRY_RET(expr, retval) |
Enumerations | |
| enum class | nros::ErrorCode : int32_t { nros::Ok = 0 , nros::Error = -1 , nros::Timeout = -2 , nros::InvalidArgument = -3 , nros::NotInitialized = -4 , nros::Full = -5 , nros::TryAgain = -6 , nros::Reentrant = -7 , nros::TransportError = -100 } |
nros::Result, nros::ErrorCode, and the NROS_TRY macro.
See Error Codes for the full code table and recovery guidance.
| #define NROS_CHECK | ( | expr | ) |
Like NROS_TRY but for void-returning callers (RTOS app_main(void), task entry points, …). Logs the failure via the same NROS_TRY_LOG hook as NROS_TRY_RET and bails with a bare return;.
| #define NROS_TRY | ( | expr | ) |
Early-return macro for error propagation (replaces try/catch).
Usage:
| #define NROS_TRY_LOG | ( | file, | |
| line, | |||
| expr, | |||
| ret | |||
| ) | ((void)(file), (void)(line), (void)(expr), (void)(ret)) |
Like NROS_TRY but for callers that need a custom return value (e.g. int main examples returning 1 on failure).
Phase 123.B.1 — when NROS_CPP_STD is defined (POSIX / Zephyr native_sim / threadx-linux + any host with <cstdio>), the default logger writes [nros] <file>:<line> <expr> -> <ret> to stderr so first-time users see failures immediately. Embedded builds without stdio fall through to the silent default.
Override NROS_TRY_LOG(file, line, expr, ret) before including this header to attach a custom logger (Zephyr's LOG_ERR, semihosting, defmt, etc.). Opt out entirely with #define NROS_TRY_LOG(file, line, expr, ret) ((void)0).
| #define NROS_TRY_RET | ( | expr, | |
| retval | |||
| ) |