DATRW++ library: seismic data I/O with multiple formats
error.h
Go to the documentation of this file.
1 /*! \file error.h
2  * \brief exception class declaration for libdatrwxx (prototypes)
3  *
4  * ----------------------------------------------------------------------------
5  *
6  * \author Thomas Forbriger
7  * \date 30/03/2004
8  *
9  * exception class declaration for libdatrwxx (prototypes)
10  *
11  * ----
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25  * ----
26  *
27  * Copyright (c) 2004 by Thomas Forbriger (BFO Schiltach)
28  *
29  * REVISIONS and CHANGES
30  * - 30/03/2004 V1.0 Thomas Forbriger (thof)
31  * - 28/04/2006 V1.1 provide explicit virtual destructor
32  * - 07/07/2006 V1.2 provide non-fatal behaviour
33  * - 06/09/2011 V1.3 introduced report_deprecated
34  * - 22/07/2014 V1.4 thof: report comments prior to throwing exception
35  * provide warning macro
36  * - 05/07/2016 V1.5 thof: operate with string containers rather than
37  * with pointer to character arrays
38  * - 07/07/2016 V1.6 thof: move class exception to separate header
39  * - 08/07/2016 V1.7 thof:
40  * - move report functions to separate compilation unit
41  * - create multiline messages
42  * - remove specific multiline macros
43  * - 11/07/2016 V1.8 thof:
44  * - support multi-line abort message
45  *
46  * ============================================================================
47  */
48 
49 // include guard
50 #ifndef DATRW_ERROR_H_VERSION
51 
52 #define DATRW_ERROR_H_VERSION \
53  "DATRW_ERROR_H V1.8"
54 
55 #include <iostream>
56 #include <sstream>
57 #include <datrwxx/report.h>
58 #include <datrwxx/exception.h>
59 
60 /*! \defgroup group_error Internal utility: Error handling module
61  */
62 
63 /*======================================================================*/
64 //
65 // preprocessor macros
66 // ===================
67 
68 /*! \brief Check an assertion and report by throwing an exception.
69  *
70  * \ingroup group_error
71  * \param C assert condition
72  * \param M message (may use output operators;
73  * possibly containing newline characters)
74  * \param E exception class to throw
75  */
76 #define DATRW_Xassert(C,M,E) \
77  if (!(C)) { \
78  { \
79  std::ostringstream oss; \
80  oss << M; \
81  throw( E ( oss.str() , __FILE__, __LINE__, #C )); \
82  } \
83  }
84 
85 /*! \brief Check an assertion and report by throwing an exception.
86  *
87  * \ingroup group_error
88  * \param C assert condition
89  * \param M message (may use output operators;
90  * possibly containing newline characters)
91  */
92 #define DATRW_assert(C,M) DATRW_Xassert( C , M , datrw::Exception )
93 
94 /*! \brief Abort and give a message.
95  *
96  * \ingroup group_error
97  * \param M message (may use output operators;
98  * possibly containing newline characters)
99  * \param E exception class to throw
100  */
101 #define DATRW_abort(M) \
102  { \
103  std::ostringstream oss; \
104  oss << M; \
105  throw( datrw::Exception ( oss.str() , __FILE__, __LINE__ )); \
106  }
107 
108 #define DATRW_illegal DATRW_abort("Illegal call within the library!\n" \
109  "This must be considered a bug. Please report the issue at\n" \
110  "https://git.scc.kit.edu/Seitosh/Seitosh")
111 
112 
113 /*! \brief Check an assertion and report only.
114  *
115  * \ingroup group_error
116  * \param C assert condition
117  * \param M message (may use output operators;
118  * possibly containing newline characters)
119  */
120 #define DATRW_report_assert(C,M) \
121  if (!(C)) { \
122  { \
123  std::ostringstream oss; \
124  oss << M; \
125  datrw::util::report_violation(datrw::util::Fnonfatal, \
126  oss.str(), __FILE__, __LINE__, #C); \
127  } \
128  }
129 
130 /*! \brief Macro to distinguish between fatal and non fatal assertions.
131  *
132  * \ingroup group_error
133  * \param F true for non fatal behaviour
134  * \param C assert condition
135  * \param M message (may use output operators;
136  * possibly containing newline characters)
137  */
138 #define DATRW_nonfatal_assert(F,C,M) \
139  if (F) { DATRW_report_assert(C,M) } else { DATRW_assert(C,M) }
140 
141 /*! \brief Report a warning.
142  *
143  * \ingroup group_error
144  * \param N name of function
145  * \param M message (may use output operators;
146  * possibly containing newline characters)
147  */
148 #define DATRW_warning(N,M) \
149  { \
150  std::ostringstream oss; \
151  oss << "in function \"" << N << "\":\n" << M; \
152  datrw::util::report_violation(datrw::util::Fwarning, \
153  oss.str(), __FILE__, __LINE__, ""); \
154  }
155 
156 #endif // DATRW_ERROR_H_VERSION (includeguard)
157 
158 /* ----- END OF error.h ----- */
libdatrwxx exception class (prototypes)
report errors and warnings (prototypes)