PDI 1.0.1

Data exchange made easy

error.h
1 /*******************************************************************************
2  * Copyright (C) 2015-2020 Commissariat a l'energie atomique et aux energies alternatives (CEA)
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of CEA nor the names of its contributors may be used to
13  * endorse or promote products derived from this software without specific
14  * prior written permission.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  ******************************************************************************/
24 
25 #ifndef PDI_ERROR_H_
26 #define PDI_ERROR_H_
27 
28 #include <exception>
29 #include <string>
30 
31 #include <paraconf.h>
32 
33 #include <pdi/pdi_fwd.h>
34 
35 #include <spdlog/fmt/fmt.h>
36 
37 namespace PDI {
38 
39 class PDI_EXPORT Error:
40  public std::exception
41 {
42 protected:
44 
45  std::string m_what;
46 
47 public:
54  template<typename S, typename... Args>
55  Error(PDI_status_t errcode, const S& format_str, Args&& ... args):
56  m_status{errcode},
57  m_what{fmt::format(format_str, std::forward<Args>(args)...)}
58  {}
59 
60  Error(PDI_status_t errcode, const char* fmt);
61 
62  const char* what() const noexcept override;
63 
64  PDI_status_t status() const noexcept;
65 
66 };
67 
68 class PDI_EXPORT Unavailable_error:
69  public Error
70 {
71 public:
72  template<typename S, typename... Args>
73  Unavailable_error(const S& format_str, Args&& ... args):
74  Error(PDI_UNAVAILABLE, std::string("Unavailable_error: ") + format_str, std::forward<Args>(args)...)
75  {}
76 
78 
79  Unavailable_error(const Unavailable_error&) = default;
80 };
81 
82 class PDI_EXPORT Config_error:
83  public Error
84 {
85 public:
86  template<typename S, typename... Args>
87  Config_error(const S& format_str, Args&& ... args):
88  Error(PDI_ERR_CONFIG, std::string("Config_error: ") + format_str, std::forward<Args>(args)...)
89  {}
90 
91  Config_error(Config_error&&) = default;
92 
93  Config_error(const Config_error&) = default;
94 };
95 
96 class PDI_EXPORT Value_error:
97  public Error
98 {
99 public:
100  template<typename S, typename... Args>
101  Value_error(const S& format_str, Args&& ... args):
102  Error(PDI_ERR_VALUE, std::string("Value_error: ") + format_str, std::forward<Args>(args)...)
103  {}
104 
105  Value_error(Value_error&&) = default;
106 
107  Value_error(const Value_error&) = default;
108 };
109 
110 class PDI_EXPORT Plugin_error:
111  public Error
112 {
113 public:
114  template<typename S, typename... Args>
115  Plugin_error(const S& format_str, Args&& ... args):
116  Error(PDI_ERR_PLUGIN, std::string("Plugin_error: ") + format_str, std::forward<Args>(args)...)
117  {}
118 
119  Plugin_error(Plugin_error&&) = default;
120 
121  Plugin_error(const Plugin_error&) = default;
122 };
123 
124 class PDI_EXPORT Impl_error:
125  public Error
126 {
127 public:
128  template<typename S, typename... Args>
129  Impl_error(const S& format_str, Args&& ... args):
130  Error(PDI_ERR_IMPL, std::string("Impl_error: ") + format_str, std::forward<Args>(args)...)
131  {}
132 
133  Impl_error(Impl_error&&) = default;
134 
135  Impl_error(const Impl_error&) = default;
136 };
137 
138 class PDI_EXPORT System_error:
139  public Error
140 {
141 public:
142  template<typename S, typename... Args>
143  System_error(const S& format_str, Args&& ... args):
144  Error(PDI_ERR_SYSTEM, std::string("System_error: ") + format_str, std::forward<Args>(args)...)
145  {}
146 
147  System_error(System_error&&) = default;
148 
149  System_error(const System_error&) = default;
150 };
151 
152 class PDI_EXPORT State_error:
153  public Error
154 {
155 public:
156  template<typename S, typename... Args>
157  State_error(const S& format_str, Args&& ... args):
158  Error(PDI_ERR_STATE, std::string("State_error: ") + format_str, std::forward<Args>(args)...)
159  {}
160 
161  State_error(State_error&&) = default;
162 
163  State_error(const State_error&) = default;
164 };
165 
166 class PDI_EXPORT Right_error:
167  public Error
168 {
169 public:
170  template<typename S, typename... Args>
171  Right_error(const S& format_str, Args&& ... args):
172  Error(PDI_ERR_RIGHT, std::string("Right_error: ") + format_str, std::forward<Args>(args)...)
173  {}
174 
175  Right_error(Right_error&&) = default;
176 
177  Right_error(const Right_error&) = default;
178 };
179 
180 class PDI_EXPORT Type_error:
181  public Error
182 {
183 public:
184  template<typename S, typename... Args>
185  Type_error(const S& format_str, Args&& ... args):
186  Error(PDI_ERR_TYPE, std::string("Type_error: ") + format_str, std::forward<Args>(args)...)
187  {}
188 
189  Type_error(Type_error&&) = default;
190 
191  Type_error(const Type_error&) = default;
192 };
193 
194 } // namespace PDI
195 
196 #endif // PDI_ERROR_H_
Definition: error.h:180
Definition: error.h:110
Right_error(const S &format_str, Args &&... args)
Definition: error.h:171
Type_error(const S &format_str, Args &&... args)
Definition: error.h:185
System_error(const S &format_str, Args &&... args)
Definition: error.h:143
PDI_status_t m_status
Definition: error.h:43
Value_error(const S &format_str, Args &&... args)
Definition: error.h:101
on an input call, no such data is available
Definition: pdi.h:77
Unavailable_error(const S &format_str, Args &&... args)
Definition: error.h:73
A system error occured (OS, etc.)
Definition: pdi.h:87
Impl_error(const S &format_str, Args &&... args)
Definition: error.h:129
STL namespace.
A value expression is invalid.
Definition: pdi.h:81
The configuration file is invalid.
Definition: pdi.h:79
State_error(const S &format_str, Args &&... args)
Definition: error.h:157
A call to a function has been made at a wrong time (e.g.
Definition: pdi.h:91
Invalid type error.
Definition: pdi.h:95
Definition: error.h:68
Tried to load a non-existing plugin.
Definition: pdi.h:83
Definition: error.h:152
Definition: error.h:124
Definition: error.h:96
Definition: error.h:82
Config_error(const S &format_str, Args &&... args)
Definition: error.h:87
PDI_status_t
Error codes of PDI.
Definition: pdi.h:73
Definition: error.h:166
A conflict of onwership over a content has been raised.
Definition: pdi.h:93
Plugin_error(const S &format_str, Args &&... args)
Definition: error.h:115
Error(PDI_status_t errcode, const S &format_str, Args &&... args)
Creates a PDI error.
Definition: error.h:55
std::string m_what
Definition: error.h:45
Definition: array_datatype.h:37
Definition: error.h:138
Definition: error.h:39
Implementation limitation (typically an unimplemented feature)
Definition: pdi.h:85