UnexpectedEnumValueException.h
Go to the documentation of this file.
1 #pragma once
2 
4 
6 
8 {
9 
10  /**
11  * @brief Indicates that an unexpected value of an enum was encountered.
12  */
13  class UnexpectedEnumValueException : public armarx::LocalException
14  {
15  public:
16 
17  /**
18  * @brief Constructor.
19  * @param enumName the name of the enum type
20  * @param value the encountered value (cast to int if needed)
21  */
22  UnexpectedEnumValueException(const std::string& enumName, int value);
23 
24  /**
25  * @brief Constructor.
26  * @param enumName the name of the enum type
27  * @param value the encountered value (is cast to int)
28  */
29  template <typename EnumT>
30  UnexpectedEnumValueException(const std::string& enumName, EnumT value) :
31  UnexpectedEnumValueException(enumName, static_cast<int>(value))
32  {}
33 
34  /// Virtual destructor.
35  virtual ~UnexpectedEnumValueException() override = default;
36 
37 
38  /// Get the name of the enum type.
39  const std::string& getEnumName() const;
40 
41  /// Get the encountered enum value.
42  int getValue() const;
43 
44 
45  private:
46 
47  /// The name of the enum type.
48  std::string enumName;
49 
50  /// The encountered value (cast to int).
51  int value;
52 
53  };
54 
55 }
56 
57 /**
58  * Throw an UnexpectedEnumValueException.
59  * Pass EnumType as symbol (it will be converted to a string).
60  */
61 #define ARMARX_UNEXPECTED_ENUM_VALUE(EnumType, value) \
62  throw ::armarx::exceptions::local::UnexpectedEnumValueException(#EnumType, (value));
armarx::exceptions::local::UnexpectedEnumValueException::~UnexpectedEnumValueException
virtual ~UnexpectedEnumValueException() override=default
Virtual destructor.
LocalException.h
armarx::exceptions::local::UnexpectedEnumValueException
Indicates that an unexpected value of an enum was encountered.
Definition: UnexpectedEnumValueException.h:13
trace.h
armarx::exceptions::local::UnexpectedEnumValueException::UnexpectedEnumValueException
UnexpectedEnumValueException(const std::string &enumName, int value)
Constructor.
Definition: UnexpectedEnumValueException.cpp:10
armarx::exceptions::local
Definition: DynamicLibraryException.h:31
armarx::exceptions::local::UnexpectedEnumValueException::getEnumName
const std::string & getEnumName() const
Get the name of the enum type.
Definition: UnexpectedEnumValueException.cpp:17
armarx::exceptions::local::UnexpectedEnumValueException::getValue
int getValue() const
Get the encountered enum value.
Definition: UnexpectedEnumValueException.cpp:22
armarx::exceptions::local::UnexpectedEnumValueException::UnexpectedEnumValueException
UnexpectedEnumValueException(const std::string &enumName, EnumT value)
Constructor.
Definition: UnexpectedEnumValueException.h:30