Line data Source code
1 : /**
2 : * @file
3 : *
4 : * @brief
5 : *
6 : * @copyright BSD License (see LICENSE.md or https://www.libelektra.org)
7 : */
8 :
9 : #ifndef ELEKTRA_KEY_EXCEPT_HPP
10 : #define ELEKTRA_KEY_EXCEPT_HPP
11 :
12 : #ifndef USER_DEFINED_EXCEPTIONS
13 :
14 : namespace kdb
15 : {
16 :
17 527 : class Exception : public std::exception
18 : {
19 : public:
20 0 : virtual const char * what () const throw ()
21 : {
22 0 : return "Exception thrown by Elektra";
23 : }
24 : };
25 :
26 216 : class KeyException : public Exception
27 : {
28 : public:
29 0 : virtual const char * what () const throw ()
30 : {
31 : return "Exception thrown by a Key, typically "
32 : "because you called a method on a null key. "
33 0 : "Make sure to check this with !key first";
34 : }
35 : };
36 :
37 18 : class KeyNotFoundException : public Exception
38 : {
39 : public:
40 18 : explicit KeyNotFoundException (std::string message) : m_str (message)
41 : {
42 6 : }
43 :
44 0 : virtual const char * what () const throw ()
45 : {
46 0 : return m_str.c_str ();
47 : }
48 :
49 : private:
50 : std::string m_str;
51 : };
52 :
53 28 : class KeyTypeMismatch : public KeyException
54 : {
55 : public:
56 0 : virtual const char * what () const throw ()
57 : {
58 : return "Binary/String key mismatch, use proper "
59 0 : "getString()/getBinary() or use getValue() to get both.";
60 : }
61 : };
62 :
63 112 : class KeyTypeConversion : public KeyException
64 : {
65 : public:
66 0 : virtual const char * what () const throw ()
67 : {
68 : return "Could not convert data to requested type. "
69 : "Use get(Meta)<std::string> respectively get(Meta)<const Key> for more generic access "
70 0 : "or specialize the template methods with your type.";
71 : }
72 : };
73 :
74 :
75 76 : class KeyInvalidName : public KeyException
76 : {
77 : public:
78 1 : virtual const char * what () const throw ()
79 : {
80 : return "Invalid Keyname: keyname needs to start with /, spec/, proc/, dir/, user/ or system/ "
81 1 : "or maybe you tried to change a key that is already in a KeySet.";
82 : }
83 : };
84 : } // namespace kdb
85 :
86 : #endif
87 :
88 : #endif
|