TF++, Miscellaneous classes and modules in C++:
error.h
Go to the documentation of this file.
1 
40 // include guard
41 #ifndef TF_ERROR_H_VERSION
42 
43 #define TF_ERROR_H_VERSION \
44  "TF_ERROR_H V1.3"
45 
46 #include<stack>
47 
48 namespace tfxx {
49 
63 namespace error {
64 
78  class Exception
79  {
80  public:
82  Exception();
84  Exception(const char* message);
86  Exception(const char* message,
87  const char* condition);
89  Exception(const char* message,
90  const char* file,
91  const int& line,
92  const char* condition);
94  Exception(const char* message,
95  const char* file,
96  const int& line);
98  virtual ~Exception() { }
100  virtual void report() const;
102  static void report_on_construct();
104  static void dont_report_on_construct();
106  static void restore_report_state();
107  protected:
109  { return Mreport_on_construct; }
110  private:
112  void base_report() const;
114  static bool Mreport_on_construct;
116  const char* Mmessage;
118  const char* Mfile;
120  int Mline;
122  const char* Mcondition;
124  static std::stack<bool> Mprevious_report_state;
125  }; // class exception
126 
135  void report_violation(const char* message,
136  const char* file,
137  const int& line,
138  const char* condition);
139 
147  void report_deprecated(const char* function,
148  const char* reason);
149 
150 } // namespace error
151 
152 } // namespace tfxx
153 
154 /*======================================================================*/
155 //
156 // preprocessor macros
157 // ===================
158 
166 #define TFXX_Xassert(C,M,E) \
167  if (!(C)) { throw( E ( M , __FILE__, __LINE__, #C )); }
168 
175 #define TFXX_assert(C,M) TFXX_Xassert( C , M , tfxx::error::Exception )
176 
183 #define TFXX_abort(M) \
184  throw( tfxx::error::Exception ( M , __FILE__, __LINE__ ))
185 
186 #define TFXX_illegal TFXX_abort("illegal call!")
187 
196 #define TFXX_report_assert(C,M,V) \
197  if (!(C)) { \
198  tfxx::error::report_violation(M, __FILE__, __LINE__, #C); \
199  std::cerr << "* comment: " << V << std::endl; \
200  std::cerr << std::endl; \
201  std::cerr.flush(); \
202  }
203 
213 #define TFXX_nonfatal_assert(F,C,M,V) \
214  if (F) { TFXX_report_assert(C,M,V) } else { TFXX_assert(C,M) }
215 
216 #endif // TF_ERROR_H_VERSION (includeguard)
217 
218 /* ----- END OF error.h ----- */
virtual ~Exception()
provide explicit virtual destructor
Definition: error.h:98
static void restore_report_state()
Restore previous report state.
Definition: error.cc:98
void report_deprecated(const char *function, const char *reason)
report deprecated function
Definition: error.cc:155
static void dont_report_on_construct()
Issue NO screen report on construction of exception.
Definition: error.cc:91
bool report_on_construct_is_true() const
Definition: error.h:108
static bool Mreport_on_construct
Shall we print to cerr at construction time?
Definition: error.h:114
const char * Mfile
pointer to file name string
Definition: error.h:118
int Mline
pointer to line number in source file
Definition: error.h:120
static std::stack< bool > Mprevious_report_state
a place to store previous report state
Definition: error.h:124
static void report_on_construct()
Issue a screen report on construction of exception.
Definition: error.cc:84
const char * Mcondition
pointer to assertion condition text string
Definition: error.h:122
const char * Mmessage
pointer to message string
Definition: error.h:116
Base class for exceptions.
Definition: error.h:78
virtual void report() const
Screen report.
Definition: error.cc:108
Exception()
Creates exception with no explaning comments.
Definition: error.cc:53
void report_violation(const char *message, const char *file, const int &line, const char *condition)
report violation of assertion
Definition: error.cc:141
Namespace containing all code of library libtfxx.
void base_report() const
Screen report.
Definition: error.cc:114