mxlib
c++ tools for analyzing astronomical data and other tasks by Jared R. Males. [git repo]
Loading...
Searching...
No Matches
mxErrorOld.hpp
Go to the documentation of this file.
1/** \file mxErrorOld.hpp
2 * \author Jared R. Males (jaredmales@gmail.com)
3 * \brief Old version. Deprecated. Declares and defines the mxlib error reporting system.
4 * \ingroup error_handling_files
5 *
6 */
7
8//***********************************************************************//
9// Copyright 2015, 2016, 2017 Jared R. Males (jaredmales@gmail.com)
10//
11// This file is part of mxlib.
12//
13// mxlib is free software: you can redistribute it and/or modify
14// it under the terms of the GNU General Public License as published by
15// the Free Software Foundation, either version 3 of the License, or
16// (at your option) any later version.
17//
18// mxlib is distributed in the hope that it will be useful,
19// but WITHOUT ANY WARRANTY; without even the implied warranty of
20// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21// GNU General Public License for more details.
22//
23// You should have received a copy of the GNU General Public License
24// along with mxlib. If not, see <http://www.gnu.org/licenses/>.
25//***********************************************************************//
26
27#ifndef __mxErrorOld__
28#define __mxErrorOld__
29
30
31/** \addtogroup error_macros
32 *
33 * mxlib components use these macros to report errors to the user, which by default are wrappers for mx::error_report
34 * and mx::errno_report. This behavior can be changed with preprocessor defines.
35 *
36 * To completely suppress all mxlib error reporting, include the following before includng any mxlib headers
37 * \code
38 * #define MX_NO_ERROR_REPORTS
39 * \endcode
40 */
41
42
43/** \def MX_NO_ERROR_REPORTS
44 * \brief If this is defined, then no errors are reported.
45 * \ingroup error_macros
46 */
47#ifdef MX_NO_ERROR_REPORTS
48
49 // Just defining these as empty macros, though this is currently untested.
50 /** \todo test MX_NO_ERROR_REPORTS */
51
52 #define mxError( esrc, ecode, expl )
53 #define mxPError( esrc, ecode, expl )
54
55#else
56
57 #ifndef mxError
58
59 #include <iostream>
60
61 /** \def mxError
62 * \brief This reports an mxlib specific error
63 *
64 * Can be predefined to change the error reporting of mxlib.
65 *
66 * \param[in] esrc is intended to identify the component (i.e. the class name)
67 * \param[in] ecode is an errno erro code
68 * \param[in] expl [optional] if more information can be provided, use this to inform the user.
69 *
70 * \ingroup error_macros
71 */
72 #define mxError( esrc, ecode, expl ) \
73 std::cerr << "\n" << mx::error_report( esrc, ecode, __FILE__, __LINE__, expl ) << "\n";
74
75 #endif // mxError
76
77 #ifndef mxPError
78
79 #include <iostream>
80
81 /** \def mxPError
82 * \brief This reports a standard library error, taking after perror.
83 *
84 * Can be pre-defined to change the error reporting of mxlib.
85 *
86 * \param[in] esrc is intended to identify the component (i.e. the class name)
87 * \param[in] ecode is an errno erro code
88 * \param[in] expl [optional] if more information can be provided, use this to inform the user.
89 *
90 * \addtogroup error_macros
91 */
92 #define mxPError( esrc, ecode, expl ) \
93 std::cerr << "\n" << mx::errno_report( esrc, ecode, __FILE__, __LINE__, expl ) << "\n";
94
95 #endif // mxPError
96
97#endif // MX_NO_ERROR_REPORTS
98
99
100
101namespace mx
102{
103
104/** \defgroup mxe_errors mxlib Error Codes
105 * \ingroup error_handling_old
106 */
107
108/** \def MXE_INVALIDARG
109 * \brief An argument was invalid.
110 * \ingroup mxe_errors
111 */
112#define MXE_INVALIDARG 25
113#define MXE_INVALIDARG_NAME "MXE_INVALIDARG"
114#define MXE_INVALIDARG_MSG "An argument was invalid."
115
116/** \def MXE_INVALIDCONFIG
117 * \brief A config setting was invalid.
118 * \ingroup mxe_errors
119 */
120#define MXE_INVALIDCONFIG 27
121#define MXE_INVALIDCONFIG_NAME "MXE_INVALIDCONFIG"
122#define MXE_INVALIDCONFIG_MSG "A config setting was invalid."
123
124/** \def MXE_NOTIMPL
125 * \brief A component or technique is not implemented.
126 * \ingroup mxe_errors
127 */
128#define MXE_NOTIMPL 30
129#define MXE_NOTIMPL_NAME "MXE_NOTIMPL"
130#define MXE_NOTIMPL_MSG "A component or technique is not implemented."
131
132/** \def MXE_PARAMNOTSET
133 * \brief A parameter was not set
134 * \ingroup mxe_errors
135 */
136#define MXE_PARAMNOTSET 35
137#define MXE_PARAMNOTSET_NAME "MXE_PARAMNOTSET"
138#define MXE_PARAMNOTSET_MSG "A parameter was not set."
139
140/** \def MXE_ENVNOTSET
141 * \brief An environment variable is not set
142 * \ingroup mxe_errors
143 */
144#define MXE_ENVNOTSET 36
145#define MXE_ENVNOTSET_NAME "MXE_ENVNOTSET"
146#define MXE_ENVNOTSET_MSG "An environment variable is not set."
147
148/** \def MXE_NOTFOUND
149 * \brief An item was not found
150 * \ingroup mxe_errors
151 */
152#define MXE_NOTFOUND 40
153#define MXE_NOTFOUND_NAME "MXE_NOTFOUND"
154#define MXE_NOTFOUND_MSG "An item was not found."
155
156/** \def MXE_SIZEERR
157 * \brief A size was invalid or calculated incorrectly
158 * \ingroup mxe_errors
159 */
160#define MXE_SIZEERR 55
161#define MXE_SIZEERR_NAME "MXE_SIZEERR"
162#define MXE_SIZEERR_MSG "A size was invalid or calculated incorrectly."
163
164/** \def MXE_ALLOCERR
165 * \brief An error occurred during memory allocation.
166 * \ingroup mxe_errors
167 */
168#define MXE_ALLOCERR 60
169#define MXE_ALLOCERR_NAME "MXE_ALLOCERR"
170#define MXE_ALLOCERR_MSG "An error occurred during memory allocation."
171
172/** \def MXE_FREEERR
173 * \brief An error occurred during memory de-allocation.
174 * \ingroup mxe_errors
175 */
176#define MXE_FREEERR 65
177#define MXE_FREEERR_NAME "MXE_FREEERR"
178#define MXE_FREEERR_MSG "An error occurred during memory de-allocation."
179
180/** \def MXE_PARSEERR
181 * \brief A parsing error occurred.
182 * \ingroup mxe_errors
183 */
184#define MXE_PARSEERR 75
185#define MXE_PARSEERR_NAME "MXE_PARSEERR"
186#define MXE_PARSEERR_MSG "A parsing error occurred."
187
188/** \def MXE_FILEOERR
189 * \brief An error occurred while opening a file.
190 * \ingroup mxe_errors
191 */
192#define MXE_FILEOERR 1034
193#define MXE_FILEOERR_NAME "MXE_FILEOERR"
194#define MXE_FILEOERR_MSG "An error occurred while opening a file."
195
196/** \def MXE_FILEWERR
197 * \brief An error occurred while writing to a file.
198 * \ingroup mxe_errors
199 */
200#define MXE_FILEWERR 1044
201#define MXE_FILEWERR_NAME "MXE_FILEWERR"
202#define MXE_FILEWERR_MSG "An error occurred while writing to a file."
203
204/** \def MXE_FILERERR
205 * \brief An error occurred while reading from a file.
206 * \ingroup mxe_errors
207 */
208#define MXE_FILERERR 1049
209#define MXE_FILERERR_NAME "MXE_FILERERR"
210#define MXE_FILERERR_MSG "An error occurred while reading from a file."
211
212/** \def MXE_FILECERR
213 * \brief An error occurred while closing a file.
214 * \ingroup mxe_errors
215 */
216#define MXE_FILECERR 1054
217#define MXE_FILECERR_NAME "MXE_FILECERR"
218#define MXE_FILECERR_MSG "An error occurred while closing a file."
219
220/** \def MXE_FILENOTFOUND
221 * \brief The file was not found.
222 * \ingroup mxe_errors
223 */
224#define MXE_FILENOTFOUND 1059
225#define MXE_FILENOTFOUND_NAME "MXE_FILENOTFOUND"
226#define MXE_FILENOTFOUND_MSG "The file was not found."
227
228/** \def MXE_PROCERR
229 * \brief An error occrred while starting a process.
230 * \ingroup mxe_errors
231 */
232#define MXE_PROCERR 2001
233#define MXE_PROCERR_NAME "MXE_PROCERR"
234#define MXE_PROCERR_MSG "An error occured while starting a process."
235
236/** \def MXE_TIMEOUT
237 * \brief A timeout occurred.
238 * \ingroup mxe_errors
239 */
240#define MXE_TIMEOUT 2322
241#define MXE_TIMEOUT_NAME "MXE_TIMEOUT"
242#define MXE_TIMEOUT_MSG "A timeout occurred."
243
244/** \def MXE_LIBERR
245 * \brief An error was returned by a library.
246 * \ingroup mxe_errors
247 */
248#define MXE_LIBERR 4000
249#define MXE_LIBERR_NAME "MXE_LIBERR"
250#define MXE_LIBERR_MSG "An error was returned by a library."
251
252/** \def MXE_EXCEPTTHROWN
253 * \brief An exception was thrown.
254 *
255 * This gets used mainly to re-throw as a nested exception.
256 *
257 * \ingroup mxe_errors
258 */
259#define MXE_EXCEPTTHROWN 4010
260#define MXE_EXCEPTTHROWN_NAME "MXE_EXCEPTTHROWN"
261#define MXE_EXCEPTTHROWN_MSG "An exception was thrown."
262
263/** \def MXE_GNUPLOTERR
264 * \brief An error was returned by gnuplot.
265 * \ingroup mxe_errors
266 */
267#define MXE_GNUPLOTERR 4567
268#define MXE_GNUPLOTERR_NAME "MXE_GNUPLOTERR"
269#define MXE_GNUPLOTERR_MSG "An error was returned by gnuplot."
270
271/** \def MXE_LAPACKERR
272 * \brief An error was returned by Lapack.
273 * \ingroup mxe_errors
274 */
275#define MXE_LAPACKERR 6890
276#define MXE_LAPACKERR_NAME "MXE_LAPACKERR"
277#define MXE_LAPACKERR_MSG "An error was returned by Lapack."
278
279/// Return the name for an mxlib error code
280/**
281 *
282 * \returns the name of the macro corresponding to the error code.
283 *
284 * \ingroup error_handling_old
285 */
286std::string MXE_CodeToName( int ec /**< [in] the error code */ );
287
288/// Return the description for an mxlib error code
289/**
290 *
291 * \returns the description for and error code.
292 *
293 * \ingroup error_handling_old
294 */
295std::string MXE_CodeToDescription( int ec /**< [in] the error code */ );
296
297/// Return the macro name and a message for a standard errno code
298/**
299 *
300 * \returns the name of the macro corresponding to the code.
301 *
302 * \ingroup error_handling_old
303 */
304std::string errno_CodeToName( int ec /**< [in] the error code */ );
305
306/// Construct a rich error report given an mxlib error code
307/**
308 *
309 * \return the formatted error report.
310 *
311 * \ingroup error_handling_old
312 */
313std::string error_report(
314 const std::string &source, ///< [in] is intended to identify the mxlib component (i.e. the class name)
315 const int &code, ///< [in] is an MXE_* error code
316 const std::string &file, ///< [in] should be passed the __FILE__ macro
317 const int &line, ///< [in] should be passed the __LINE__ macro
318 const std::string &expl = "" ///< [in] [optional] if more information can be provided, use this to inform the user.
319);
320
321/// Construct a rich error report given a standard errno error code
322/**
323 * \return the formatted error report.
324 *
325 * \ingroup error_handling_old
326 */
327std::string errno_report(
328 const std::string &source, ///< [in] intended to identify the component (i.e. the class name)
329 int ec, ///< [in] an errno erro code
330 const std::string &file, ///< [in] file should be passed the __FILE__ macro
331 const int &line, ///< [in] line should be passed the __LINE__ macro
332 const std::string &expl = "" ///< [in] [optional] if more information can be provided, use this to inform the user.
333);
334
335
336} // namespace mx
337
338#endif //__mxErrorOld__
std::string MXE_CodeToName(int ec)
Return the name for an mxlib error code.
Definition mxError.cpp:33
std::string errno_CodeToName(int ec)
Return the macro name and a message for a standard errno code.
Definition mxError.cpp:133
std::string MXE_CodeToDescription(int ec)
Return the description for an mxlib error code.
Definition mxError.cpp:83
std::string errno_report(const std::string &source, int ec, const std::string &file, const int &line, const std::string &expl="")
Construct a rich error report given a standard errno error code.
Definition mxError.cpp:483
error_t error_report(const error_t &code, const std::string &expl, const std::source_location &loc=std::source_location::current())
Print a report to stderr given an mxlib error_t code and explanation and return the code.
Definition mxError.hpp:394
The mxlib c++ namespace.
Definition mxError.hpp:40