Function rclcpp::exceptions::throw_from_rcl_error

Function Documentation

void rclcpp::exceptions::throw_from_rcl_error(rcl_ret_t ret, const std::string &prefix = "", const rcl_error_state_t *error_state = nullptr, reset_error_function_t reset_error = rcl_reset_error)

Throw a C++ std::exception which was created based on an rcl error.

Passing nullptr for reset_error is safe and will avoid calling any function to reset the error.

Parameters:
  • ret – the return code for the current error state

  • prefix – string to prefix to the error if applicable (not all errors have custom messages)

  • error_state – error state to create exception from, if nullptr rcl_get_error_state is used

  • reset_error – function to be called before throwing which whill clear the error state

Throws:
  • std::invalid_argument – if ret is RCL_RET_OK

  • std::runtime_error – if the rcl_get_error_state returns 0

  • RCLErrorBase – some child class exception based on ret