Skip to content

Commit c081cc8

Browse files
committed
Print error of caught exception in init
1 parent 82fe3c4 commit c081cc8

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/rtde/rtde_client.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,19 @@ bool RTDEClient::init(const size_t max_connection_attempts, const std::chrono::m
9090
}
9191

9292
unsigned int attempts = 0;
93+
std::stringstream ss;
9394
while (attempts < max_initialization_attempts)
9495
{
95-
try {
96+
try
97+
{
9698
setupCommunication(max_connection_attempts, reconnection_timeout);
97-
} catch (const UrException&) {}
98-
if (client_state_ == ClientState::INITIALIZED) {
99+
}
100+
catch (const UrException& exc)
101+
{
102+
ss << exc.what() << std::endl;
103+
}
104+
if (client_state_ == ClientState::INITIALIZED)
105+
{
99106
return true;
100107
}
101108
if (++attempts < max_initialization_attempts)
@@ -104,7 +111,6 @@ bool RTDEClient::init(const size_t max_connection_attempts, const std::chrono::m
104111
std::this_thread::sleep_for(initialization_timeout);
105112
}
106113
}
107-
std::stringstream ss;
108114
ss << "Failed to initialize RTDE client after " << max_initialization_attempts << " attempts";
109115
throw UrException(ss.str());
110116
}
@@ -711,4 +717,4 @@ std::vector<std::string> RTDEClient::splitVariableTypes(const std::string& varia
711717
return result;
712718
}
713719
} // namespace rtde_interface
714-
} // namespace urcl
720+
} // namespace urcl

tests/test_rtde_client.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -363,13 +363,14 @@ TEST_F(RTDEClientTest, connect_non_running_robot)
363363
client_.reset(
364364
new rtde_interface::RTDEClient("192.168.56.123", notifier_, resources_output_recipe_, resources_input_recipe_));
365365
auto start = std::chrono::system_clock::now();
366-
EXPECT_THROW(client_->init(2, std::chrono::milliseconds(500)), UrException);
366+
EXPECT_THROW(client_->init(2, std::chrono::milliseconds(500), 1), UrException);
367367
auto end = std::chrono::system_clock::now();
368368
auto elapsed = end - start;
369369
// This is only a rough estimate, obviously.
370370
// Since this isn't done on the loopback device, trying to open a socket on a non-existing address
371371
// takes considerably longer.
372-
EXPECT_LT(elapsed, 2 * comm::TCPSocket::DEFAULT_RECONNECTION_TIME);
372+
EXPECT_LT(std::chrono::duration_cast<std::chrono::milliseconds>(elapsed).count(),
373+
2 * comm::TCPSocket::DEFAULT_RECONNECTION_TIME.count());
373374
}
374375

375376
TEST_F(RTDEClientTest, check_all_rtde_output_variables_exist)
@@ -426,4 +427,4 @@ int main(int argc, char* argv[])
426427
}
427428

428429
return RUN_ALL_TESTS();
429-
}
430+
}

0 commit comments

Comments
 (0)