@@ -76,8 +76,9 @@ TimerBase::~TimerBase()
7676void
7777TimerBase::cancel ()
7878{
79- if (rcl_timer_cancel (timer_handle_.get ()) != RCL_RET_OK) {
80- throw std::runtime_error (std::string (" Couldn't cancel timer: " ) + rcl_get_error_string ().str );
79+ rcl_ret_t ret = rcl_timer_cancel (timer_handle_.get ());
80+ if (ret != RCL_RET_OK) {
81+ rclcpp::exceptions::throw_from_rcl_error (ret, " Couldn't cancel timer" );
8182 }
8283}
8384
@@ -95,17 +96,19 @@ TimerBase::is_canceled()
9596void
9697TimerBase::reset ()
9798{
98- if (rcl_timer_reset (timer_handle_.get ()) != RCL_RET_OK) {
99- throw std::runtime_error (std::string (" Couldn't reset timer: " ) + rcl_get_error_string ().str );
99+ rcl_ret_t ret = rcl_timer_reset (timer_handle_.get ());
100+ if (ret != RCL_RET_OK) {
101+ rclcpp::exceptions::throw_from_rcl_error (ret, " Couldn't reset timer" );
100102 }
101103}
102104
103105bool
104106TimerBase::is_ready ()
105107{
106108 bool ready = false ;
107- if (rcl_timer_is_ready (timer_handle_.get (), &ready) != RCL_RET_OK) {
108- throw std::runtime_error (std::string (" Failed to check timer: " ) + rcl_get_error_string ().str );
109+ rcl_ret_t ret = rcl_timer_is_ready (timer_handle_.get (), &ready);
110+ if (ret != RCL_RET_OK) {
111+ rclcpp::exceptions::throw_from_rcl_error (ret, " Failed to check timer" );
109112 }
110113 return ready;
111114}
@@ -114,14 +117,10 @@ std::chrono::nanoseconds
114117TimerBase::time_until_trigger ()
115118{
116119 int64_t time_until_next_call = 0 ;
117- if (
118- rcl_timer_get_time_until_next_call (
119- timer_handle_.get (),
120- &time_until_next_call) != RCL_RET_OK)
121- {
122- throw std::runtime_error (
123- std::string (
124- " Timer could not get time until next call: " ) + rcl_get_error_string ().str );
120+ rcl_ret_t ret = rcl_timer_get_time_until_next_call (
121+ timer_handle_.get (), &time_until_next_call);
122+ if (ret != RCL_RET_OK) {
123+ rclcpp::exceptions::throw_from_rcl_error (ret, " Timer could not get time until next call" );
125124 }
126125 return std::chrono::nanoseconds (time_until_next_call);
127126}
0 commit comments