diff --git a/core/roscpp/include/ros/forwards.h b/core/roscpp/include/ros/forwards.h index 6848989b..c5e1c01e 100644 --- a/core/roscpp/include/ros/forwards.h +++ b/core/roscpp/include/ros/forwards.h @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -163,6 +164,14 @@ typedef boost::shared_ptr XMLRPCManagerPtr; class PollManager; typedef boost::shared_ptr PollManagerPtr; +class Exception : public std::runtime_error +{ +public: + Exception(const std::string& what) + : std::runtime_error(what) + {} +}; + } #endif diff --git a/core/roscpp/include/ros/this_node.h b/core/roscpp/include/ros/this_node.h index f39bb447..7d5ba82e 100644 --- a/core/roscpp/include/ros/this_node.h +++ b/core/roscpp/include/ros/this_node.h @@ -33,6 +33,14 @@ namespace ros { +class InvalidNodeNameException : public ros::Exception +{ +public: + InvalidNodeNameException(const std::string& name, const std::string& reason) + : Exception("Invalid node name [" + name + "]: " + reason) + {} +}; + /** * \brief Contains functions which provide information about this process' ROS node */ diff --git a/core/roscpp/src/libros/this_node.cpp b/core/roscpp/src/libros/this_node.cpp index 4d6df5ef..c003bbe1 100644 --- a/core/roscpp/src/libros/this_node.cpp +++ b/core/roscpp/src/libros/this_node.cpp @@ -98,6 +98,11 @@ void init(const std::string& name, const M_string& remappings, uint32_t options) // It must be done before we resolve g_name, because otherwise the name will not get remapped. names::init(remappings); + if (g_name.find("/") != std::string::npos) + { + throw InvalidNodeNameException(g_name, "node names cannot contain /"); + } + g_name = names::resolve(g_namespace, g_name); if (options & init_options::AnonymousName && !disable_anon)