Exception.h
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T),
5  * Karlsruhe Institute of Technology (KIT), all rights reserved.
6  *
7  * ArmarX is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  *
11  * ArmarX is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  *
19  * @author Fabian Peller-Konrad (fabian dot peller-konrad at kit dot edu)
20  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
21  * GNU General Public License
22  */
23 
24 #pragma once
25 
26 // STD/STL
27 
28 // ArmarX
32 
33 #include <RobotAPI/interface/aron.h>
36 
38 {
39  /**
40  * @brief A base class for aron exceptions. All aron exceptions inherit from this class
41  */
42  class AronException : public armarx::LocalException
43  {
44  public:
45  AronException() = delete;
46 
47  AronException(const std::string& prettymethod, const std::string& reason) :
48  LocalException(prettymethod + ": " + reason + ".")
49  {
50  }
51 
52  AronException(const std::string& prettymethod,
53  const std::string& reason,
54  const Path& path) :
55  LocalException(prettymethod + ": " + reason + ". The path was: " + path.toString())
56  {
57  }
58 
59  /// call operator to append a message to the exception. Used by ARMARX_CHECK_AND_THROW
61  operator()(const std::string& additionalMessage = "")
62  {
63  auto currentReason = getReason();
64  if (not additionalMessage.empty())
65  {
66  setReason(currentReason + ". Additional Message: " + additionalMessage);
67  }
68  return *this;
69  }
70  };
71 
73  {
74  public:
75  AronEOFException() = delete;
76 
77  AronEOFException(const std::string& prettymethod) :
78  AronException(prettymethod,
79  "REACHED THE END OF A NON VOID METHOD. PERHAPS YOU FORGOT TO ADD A VALUE "
80  "TO SOME SWITCH-CASE STATEMEMT?.")
81  {
82  }
83  };
84 
85  /**
86  * @brief The NotImplementedYetException class
87  */
89  {
90  public:
91  NotImplementedYetException() = delete;
92 
93  NotImplementedYetException(const std::string& prettymethod) :
94  AronException(prettymethod, "This method is not yet implemented!")
95  {
96  }
97  };
98 
99  /**
100  * @brief The AronNotValidException class. Takes a dto object as input
101  */
103  {
104  public:
105  AronNotValidException() = delete;
106 
107  AronNotValidException(const std::string& prettymethod,
108  const std::string& reason,
109  const data::dto::GenericDataPtr& data) :
110  AronException(prettymethod, reason + ". The ice_id of the data was: " + data->ice_id())
111  {
112  }
113 
114  AronNotValidException(const std::string& prettymethod,
115  const std::string& reason,
116  const data::dto::GenericDataPtr& data,
117  const Path& path) :
118  AronException(prettymethod,
119  reason + ". The ice_id of the data was: " + data->ice_id(),
120  path)
121  {
122  }
123 
124  AronNotValidException(const std::string& prettymethod,
125  const std::string& reason,
126  const type::dto::GenericTypePtr& type) :
127  AronException(prettymethod, reason + ". The ice_id of the type was: " + type->ice_id())
128  {
129  }
130 
131  AronNotValidException(const std::string& prettymethod,
132  const std::string& reason,
133  const type::dto::GenericTypePtr& type,
134  const Path& path) :
135  AronException(prettymethod,
136  reason + ". The ice_id of the type was: " + type->ice_id(),
137  path)
138  {
139  }
140  };
141 
142  /**
143  * @brief The ValueNotValidException class. Only takes strings as input (convert before)
144  */
146  {
147  public:
148  ValueNotValidException() = delete;
149 
150  ValueNotValidException(const std::string& prettymethod,
151  const std::string& reason,
152  const std::string& input) :
153  AronException(prettymethod, reason + ". Got: " + input)
154  {
155  }
156 
157  ValueNotValidException(const std::string& prettymethod,
158  const std::string& reason,
159  const std::string& input,
160  const Path& path) :
161  AronException(prettymethod, reason + ". Got: " + input, path)
162  {
163  }
164 
165  ValueNotValidException(const std::string& prettymethod,
166  const std::string& reason,
167  const std::string& input,
168  const std::string& expectation) :
169  AronException(prettymethod, reason + ". Got: " + input + ". Expected: " + expectation)
170  {
171  }
172 
173  ValueNotValidException(const std::string& prettymethod,
174  const std::string& reason,
175  const std::string& input,
176  const std::string& expectation,
177  const Path& path) :
178  AronException(prettymethod,
179  reason + ". Got: " + input + ". Expected: " + expectation,
180  path)
181  {
182  }
183  };
184 } // namespace armarx::aron::error
armarx::aron::error::AronException
A base class for aron exceptions.
Definition: Exception.h:42
Descriptor.h
armarx::aron::error::AronNotValidException::AronNotValidException
AronNotValidException(const std::string &prettymethod, const std::string &reason, const type::dto::GenericTypePtr &type, const Path &path)
Definition: Exception.h:131
armarx::aron::error::AronNotValidException::AronNotValidException
AronNotValidException(const std::string &prettymethod, const std::string &reason, const data::dto::GenericDataPtr &data)
Definition: Exception.h:107
armarx::aron::error
Definition: Exception.h:37
Path.h
armarx::aron::error::NotImplementedYetException::NotImplementedYetException
NotImplementedYetException(const std::string &prettymethod)
Definition: Exception.h:93
armarx::aron::error::AronException::AronException
AronException()=delete
armarx::aron::error::ValueNotValidException::ValueNotValidException
ValueNotValidException()=delete
armarx::aron::error::AronException::AronException
AronException(const std::string &prettymethod, const std::string &reason, const Path &path)
Definition: Exception.h:52
armarx::aron::error::AronNotValidException::AronNotValidException
AronNotValidException()=delete
armarx::aron::error::NotImplementedYetException
The NotImplementedYetException class.
Definition: Exception.h:88
armarx::aron::Path
The Path class.
Definition: Path.h:36
armarx::aron::error::AronException::AronException
AronException(const std::string &prettymethod, const std::string &reason)
Definition: Exception.h:47
armarx::aron::error::ValueNotValidException
The ValueNotValidException class.
Definition: Exception.h:145
armarx::aron::error::ValueNotValidException::ValueNotValidException
ValueNotValidException(const std::string &prettymethod, const std::string &reason, const std::string &input)
Definition: Exception.h:150
armarx::aron::error::AronEOFException
Definition: Exception.h:72
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::aron::error::ValueNotValidException::ValueNotValidException
ValueNotValidException(const std::string &prettymethod, const std::string &reason, const std::string &input, const std::string &expectation)
Definition: Exception.h:165
armarx::aron::input
ReaderT::InputType & input
Definition: rw.h:19
armarx::aron::error::AronNotValidException
The AronNotValidException class.
Definition: Exception.h:102
armarx::aron::error::ValueNotValidException::ValueNotValidException
ValueNotValidException(const std::string &prettymethod, const std::string &reason, const std::string &input, const std::string &expectation, const Path &path)
Definition: Exception.h:173
ExpressionException.h
armarx::aron::error::AronNotValidException::AronNotValidException
AronNotValidException(const std::string &prettymethod, const std::string &reason, const data::dto::GenericDataPtr &data, const Path &path)
Definition: Exception.h:114
armarx::aron::error::AronEOFException::AronEOFException
AronEOFException()=delete
armarx::aron::error::AronException::operator()
AronException & operator()(const std::string &additionalMessage="")
call operator to append a message to the exception. Used by ARMARX_CHECK_AND_THROW
Definition: Exception.h:61
armarx::viz::toString
const char * toString(InteractionFeedbackType type)
Definition: Interaction.h:27
armarx::aron::error::ValueNotValidException::ValueNotValidException
ValueNotValidException(const std::string &prettymethod, const std::string &reason, const std::string &input, const Path &path)
Definition: Exception.h:157
Logging.h
armarx::aron::error::AronNotValidException::AronNotValidException
AronNotValidException(const std::string &prettymethod, const std::string &reason, const type::dto::GenericTypePtr &type)
Definition: Exception.h:124
armarx::aron::error::NotImplementedYetException::NotImplementedYetException
NotImplementedYetException()=delete
Exception.h
armarx::aron::error::AronEOFException::AronEOFException
AronEOFException(const std::string &prettymethod)
Definition: Exception.h:77