Skip to content

Commit ace8406

Browse files
committed
Reformat style error throw
Signed-off-by: Jorge Perez <jjperez@ekumenlabs.com>
1 parent e36cc76 commit ace8406

1 file changed

Lines changed: 13 additions & 14 deletions

File tree

rclcpp/src/rclcpp/timer.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@ TimerBase::~TimerBase()
7676
void
7777
TimerBase::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()
9596
void
9697
TimerBase::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

103105
bool
104106
TimerBase::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
114117
TimerBase::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

Comments
 (0)