Fortran SFF API to data I/O streams in C++
error.h
Go to the documentation of this file.
1 
37 // include guard
38 #ifndef FAPIDXX_ERROR_H_VERSION
39 
40 #define FAPIDXX_ERROR_H_VERSION \
41  "FAPIDXX_ERROR_H V1.0"
42 
43 namespace fapidxx {
44 
58 namespace error {
59 
73  class Exception
74  {
75  public:
77  Exception();
79  Exception(const char* message);
81  Exception(const char* message,
82  const char* condition);
84  Exception(const char* message,
85  const char* file,
86  const int& line,
87  const char* condition);
89  Exception(const char* message,
90  const char* file,
91  const int& line);
93  virtual ~Exception() { }
95  virtual void report() const;
97  static void report_on_construct();
99  static void dont_report_on_construct();
100  private:
102  void base_report() const;
104  static bool Mreport_on_construct;
106  const char* Mmessage;
108  const char* Mfile;
110  const int& Mline;
112  const char* Mcondition;
113  }; // class exception
114 
115  class FUException: public Exception {
116  public:
118  FUException(const int& unit,
119  const char* message,
120  const char* file,
121  const int& line,
122  const char* condition);
124  virtual ~FUException() { }
126  virtual void report() const;
127  private:
129  int Munit;
130  }; // class FUException
131 
132 } // namespace error
133 
134 } // namespace fapidxx
135 
136 /*======================================================================*/
137 //
138 // preprocessor macros
139 // ===================
140 
148 #define FAPIDXX_Xassert(C,M,E) \
149  if (!(C)) { throw( E ( M , __FILE__, __LINE__, #C )); }
150 
157 #define FAPIDXX_assert(C,M) FAPIDXX_Xassert( C , M , fapidxx::error::Exception )
158 
165 #define FAPIDXX_abort(M) \
166  throw( fapidxx::error::Exception ( M , __FILE__, __LINE__ ))
167 
168 #define FAPIDXX_illegal FAPIDXX_abort("illegal call!")
169 
178 #define FAPIDXX_report_assert(C,M,V) \
179  if (!(C)) { \
180  fapidxx::report_violation(M, __FILE__, __LINE__, #C); \
181  std::cerr << "* comment: " << V << std::endl; \
182  std::cerr << std::endl; \
183  std::cerr.flush(); \
184  }
185 
195 #define FAPIDXX_nonfatal_assert(F,C,M,V) \
196  if (F) { FAPIDXX_report_assert(C,M,V) } else { FAPIDXX_assert(C,M) }
197 
205 #define FAPIDXX_fuassert(C,U,M) \
206  if (!(C)) { throw( fapidxx::error::FUException ( U , M , __FILE__, __LINE__, #C )); }
207 
208 #endif // FAPIDXX_ERROR_H_VERSION (includeguard)
209 
210 /* ----- END OF error.h ----- */
static bool Mreport_on_construct
Shall we print to cerr at construction time?
Definition: error.h:104
virtual void report() const
Screen report.
Definition: error.cc:137
Exception()
Creates exception with no explaning comments.
Definition: error.cc:51
Definition: error.cc:44
const char * Mcondition
pointer to assertion condition text string
Definition: error.h:112
const char * Mmessage
pointer to message string
Definition: error.h:106
virtual ~FUException()
provide explicit virtual destructor
Definition: error.h:124
virtual ~Exception()
provide explicit virtual destructor
Definition: error.h:93
static void dont_report_on_construct()
Issue NO screen report on construction of exception.
Definition: error.cc:88
FUException(const int &unit, const char *message, const char *file, const int &line, const char *condition)
Create with message, failed assertion, and code position.
Definition: error.cc:127
Base class for exceptions.
Definition: error.h:73
const char * Mfile
pointer to file name string
Definition: error.h:108
void base_report() const
Screen report.
Definition: error.cc:100
virtual void report() const
Screen report.
Definition: error.cc:94
const int & Mline
pointer to line number in source file
Definition: error.h:110
int Munit
file unit
Definition: error.h:129
static void report_on_construct()
Issue a screen report on construction of exception.
Definition: error.cc:82