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