Skip to content

Commit 70b5d74

Browse files
committed
add exceptions
1 parent dc1935c commit 70b5d74

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

behaviortree_ros2/include/behaviortree_ros2/bt_action_node.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,11 @@ inline bool RosActionNode<T>::createClient(const std::string& action_name)
316316

317317
std::unique_lock lk(getMutex());
318318
auto node = node_.lock();
319+
if(!node)
320+
{
321+
throw RuntimeError("The ROS node went out of scope. RosNodeParams doesn't take the "
322+
"ownership of the node.");
323+
}
319324
action_client_key_ = std::string(node->get_fully_qualified_name()) + "/" + action_name;
320325

321326
auto& registry = getRegistry();

behaviortree_ros2/include/behaviortree_ros2/bt_service_node.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,11 @@ inline bool RosServiceNode<T>::createClient(const std::string& service_name)
282282

283283
std::unique_lock lk(getMutex());
284284
auto node = node_.lock();
285+
if(!node)
286+
{
287+
throw RuntimeError("The ROS node went out of scope. RosNodeParams doesn't take the "
288+
"ownership of the node.");
289+
}
285290
auto client_key = std::string(node->get_fully_qualified_name()) + "/" + service_name;
286291

287292
auto& registry = getRegistry();

behaviortree_ros2/include/behaviortree_ros2/bt_topic_sub_node.hpp

+5
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,11 @@ inline bool RosTopicSubNode<T>::createSubscriber(const std::string& topic_name)
250250
std::unique_lock lk(registryMutex());
251251

252252
auto shared_node = node_.lock();
253+
if(!node)
254+
{
255+
throw RuntimeError("The ROS node went out of scope. RosNodeParams doesn't take the "
256+
"ownership of the node.");
257+
}
253258
subscriber_key_ =
254259
std::string(shared_node->get_fully_qualified_name()) + "/" + topic_name;
255260

0 commit comments

Comments
 (0)