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