17 #ifndef RCUTILS__ERROR_HANDLING_H_ 18 #define RCUTILS__ERROR_HANDLING_H_ 49 #define RCUTILS_SAFE_FWRITE_TO_STDERR(msg) fwrite(msg, sizeof(char), strnlen_s(msg, 4096), stderr) 51 #define RCUTILS_SAFE_FWRITE_TO_STDERR(msg) fwrite(msg, sizeof(char), strlen(msg), stderr) 102 const char * error_msg,
const char * file,
size_t line_number,
rcutils_allocator_t allocator);
113 #define RCUTILS_CHECK_ARGUMENT_FOR_NULL(argument, error_return_type, allocator) \ 114 RCUTILS_CHECK_FOR_NULL_WITH_MSG(argument, #argument " argument is null", \ 115 return error_return_type, allocator) 127 #define RCUTILS_CHECK_FOR_NULL_WITH_MSG(value, msg, error_statement, allocator) \ 129 RCUTILS_SET_ERROR_MSG(msg, allocator); \ 144 #define RCUTILS_SET_ERROR_MSG(msg, allocator) \ 145 rcutils_set_error_state(msg, __FILE__, __LINE__, allocator); 156 #define RCUTILS_SET_ERROR_MSG_WITH_FORMAT_STRING(allocator, format_string, ...) \ 158 char * output_msg = NULL; \ 159 output_msg = rcutils_format_string(allocator, format_string, __VA_ARGS__); \ 161 RCUTILS_SET_ERROR_MSG(output_msg, allocator); \ 162 allocator.deallocate(output_msg, allocator.state); \ 164 RCUTILS_SAFE_FWRITE_TO_STDERR("Failed to allocate memory for error message\n"); \ 219 #endif // RCUTILS__ERROR_HANDLING_H_ const char * file
Definition: error_handling.h:40
struct rcutils_error_state_t rcutils_error_state_t
Struct which encapsulates the error state set by RCUTILS_SET_ERROR_MSG().
const char * rcutils_get_error_string_safe(void)
Return the error message followed by , at <file>:<line> if set, else "error not set".
void rcutils_reset_error(void)
Reset the error state by clearing any previously set error state.
int rcutils_ret_t
Definition: rcutils_ret.h:23
Encapsulation of an allocator.
Definition: allocator.h:43
rcutils_ret_t rcutils_error_state_copy(const rcutils_error_state_t *src, rcutils_error_state_t *dst)
Copy an error state into a destination error state.
const char * message
Definition: error_handling.h:39
#define RCUTILS_WARN_UNUSED
Definition: macros.h:24
const char * rcutils_get_error_string(void)
Return the error message followed by , at <file>:<line>, or NULL.
void rcutils_error_state_fini(rcutils_error_state_t *error_state)
Finalizes a copied error state.
size_t line_number
Definition: error_handling.h:41
#define RCUTILS_PUBLIC
Definition: visibility_control.h:48
const rcutils_error_state_t * rcutils_get_error_state(void)
Return an rcutils_error_state_t which was set with rcutils_set_error_state().
rcutils_allocator_t allocator
Definition: error_handling.h:42
Struct which encapsulates the error state set by RCUTILS_SET_ERROR_MSG().
Definition: error_handling.h:37
void rcutils_set_error_state(const char *error_msg, const char *file, size_t line_number, rcutils_allocator_t allocator)
Set the error message, as well as the file and line on which it occurred.
bool rcutils_error_is_set(void)
Return true if the error is set, otherwise false.