From a6ede587d81c2d0019fe87e86cf43cfbef3de674 Mon Sep 17 00:00:00 2001 From: "Tomoya.Fujita" Date: Thu, 14 May 2020 18:42:11 +0900 Subject: [PATCH] spin_some might throw exception.(#266) Signed-off-by: Tomoya.Fujita --- rclcpp/topics/minimal_publisher/not_composable.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/rclcpp/topics/minimal_publisher/not_composable.cpp b/rclcpp/topics/minimal_publisher/not_composable.cpp index 3dc44cbf..e653188b 100644 --- a/rclcpp/topics/minimal_publisher/not_composable.cpp +++ b/rclcpp/topics/minimal_publisher/not_composable.cpp @@ -36,8 +36,15 @@ int main(int argc, char * argv[]) while (rclcpp::ok()) { message.data = "Hello, world! " + std::to_string(publish_count++); RCLCPP_INFO(node->get_logger(), "Publishing: '%s'", message.data.c_str()); - publisher->publish(message); - rclcpp::spin_some(node); + try { + publisher->publish(message); + rclcpp::spin_some(node); + } catch (const rclcpp::exceptions::RCLError &e) { + RCLCPP_ERROR( + node->get_logger(), + "unexpectedly failed with %s", + e.what()); + } loop_rate.sleep(); } rclcpp::shutdown();