From 33915bf2c4f319c486e3475d7f4e3ce5ae3bbff7 Mon Sep 17 00:00:00 2001 From: Rainer Kartmann <rainer.kartmann@student.kit.edu> Date: Wed, 26 Jun 2019 11:45:46 +0200 Subject: [PATCH] Add exceptions --- VirtualRobot/CMakeLists.txt | 2 ++ VirtualRobot/XML/mujoco/exceptions.cpp | 22 +++++++++++++++++++++ VirtualRobot/XML/mujoco/exceptions.h | 27 ++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 VirtualRobot/XML/mujoco/exceptions.cpp create mode 100644 VirtualRobot/XML/mujoco/exceptions.h diff --git a/VirtualRobot/CMakeLists.txt b/VirtualRobot/CMakeLists.txt index 936be8c1f..ed462ed94 100644 --- a/VirtualRobot/CMakeLists.txt +++ b/VirtualRobot/CMakeLists.txt @@ -375,6 +375,7 @@ SET(SOURCES XML/RobotIO.cpp XML/SceneIO.cpp + XML/mujoco/exceptions.cpp XML/mujoco/BodySanitizer.cpp XML/mujoco/DummyMassBodySanitizer.cpp XML/mujoco/MergingBodySanitizer.cpp @@ -603,6 +604,7 @@ SET(INCLUDES XML/RobotIO.h XML/SceneIO.h + XML/mujoco/exceptions.h XML/mujoco/BodySanitizer.h XML/mujoco/DummyMassBodySanitizer.h XML/mujoco/MergingBodySanitizer.h diff --git a/VirtualRobot/XML/mujoco/exceptions.cpp b/VirtualRobot/XML/mujoco/exceptions.cpp new file mode 100644 index 000000000..502e90bcc --- /dev/null +++ b/VirtualRobot/XML/mujoco/exceptions.cpp @@ -0,0 +1,22 @@ +#include "exceptions.h" + + +namespace VirtualRobot::mujoco::error +{ + +NoBodyOfRobotNode::NoBodyOfRobotNode(const std::string& nodeName) : + VirtualRobotException(makeMsg(nodeName)) +{} + +std::string NoBodyOfRobotNode::makeMsg(const std::string& nodeName) +{ + return "No body of robot node " + nodeName + ". Add a node body beforehand."; +} + + +NodeIsNoJoint::NodeIsNoJoint(const std::string& nodeName) : + VirtualRobotException("Node '" + nodeName + "' is no joint node.") +{} + + +} diff --git a/VirtualRobot/XML/mujoco/exceptions.h b/VirtualRobot/XML/mujoco/exceptions.h new file mode 100644 index 000000000..b4dda1752 --- /dev/null +++ b/VirtualRobot/XML/mujoco/exceptions.h @@ -0,0 +1,27 @@ +#pragma once + +#include <VirtualRobot/VirtualRobotException.h> + + +namespace VirtualRobot::mujoco::error +{ + + /// Indicates that no body exists or has been added for a robot node. + class NoBodyOfRobotNode : public VirtualRobotException + { + public: + NoBodyOfRobotNode(const std::string& nodeName); + private: + static std::string makeMsg(const std::string& nodeName); + }; + + + /// Indicates that a robot node has to be a joint node, but is not. + class NodeIsNoJoint : public VirtualRobotException + { + public: + NodeIsNoJoint(const std::string& nodeName); + }; + + +} -- GitLab