SERIAL++ library: simple serial port access
error.h
Go to the documentation of this file.
1 
37 // include guard
38 #ifndef TF_ERROR_H_VERSION
39 
40 #define TF_ERROR_H_VERSION \
41  "TF_ERROR_H V1.0 "
42 #define TF_ERROR_H_CVSID \
43  "$Id$"
44 
45 namespace serialport {
46 
65  class Exception
66  {
67  public:
69  Exception();
71  Exception(const char* message);
73  Exception(const char* message,
74  const char* condition);
76  Exception(const char* message,
77  const char* file,
78  const int& line,
79  const char* condition);
81  Exception(const char* message,
82  const char* file,
83  const int& line);
85  virtual ~Exception() { }
87  virtual void report() const;
89  static void report_on_construct();
91  static void dont_report_on_construct();
92  protected:
94  void base_report() const;
95  private:
97  static bool Mreport_on_construct;
99  const char* Mmessage;
101  const char* Mfile;
103  const int& Mline;
105  const char* Mcondition;
106  }; // class Exception
107 
116  void report_violation(const char* message,
117  const char* file,
118  const int& line,
119  const char* condition);
120 
121 } // namespace serialport
122 
123 /*======================================================================*/
124 //
125 // preprocessor macros
126 // ===================
127 
135 #define SERIALPORT_Xassert(C,M,E) \
136  if (!(C)) { throw( E ( M , __FILE__, __LINE__, #C )); }
137 
144 #define SERIALPORT_assert(C,M) \
145  SERIALPORT_Xassert( C , M , serialport::Exception )
146 
153 #define SERIALPORT_abort(M) \
154  throw( serialport::Exception ( M , __FILE__, __LINE__ ))
155 
156 #define SERIALPORT_illegal SERIALPORT_abort("illegal call!")
157 
158 
167 #define SERIALPORT_report_assert(C,M,V) \
168  if (!(C)) { \
169  serialport::report_violation(M, __FILE__, __LINE__, #C); \
170  std::cerr << "* comment: " << V << std::endl; \
171  std::cerr << std::endl; \
172  std::cerr.flush(); \
173  }
174 
184 #define SERIALPORT_nonfatal_assert(F,C,M,V) \
185  if (F) { SERIALPORT_report_assert(C,M,V) } else { SERIALPORT_assert(C,M) }
186 
187 #endif // TF_ERROR_H_VERSION (includeguard)
188 
189 /* ----- END OF error.h ----- */
virtual ~Exception()
provide explicit virtual destructor
Definition: error.h:85
Base class for exceptions.
Definition: error.h:65
const char * Mmessage
pointer to message string
Definition: error.h:99
const char * Mcondition
pointer to assertion condition text string
Definition: error.h:105
static void report_on_construct()
Issue a screen report on construction of exception.
Definition: error.cc:85
static void dont_report_on_construct()
Issue NO screen report on construction of exception.
Definition: error.cc:91
Root namespace of library.
Definition: doxygen.txt:26
Exception()
Creates exception with no explaning comments.
Definition: error.cc:54
void base_report() const
Screen report.
Definition: error.cc:103
virtual void report() const
Screen report.
Definition: error.cc:97
const int & Mline
pointer to line number in source file
Definition: error.h:103
const char * Mfile
pointer to file name string
Definition: error.h:101
static bool Mreport_on_construct
Shall we print to cerr at construction time?
Definition: error.h:97
void report_violation(const char *message, const char *file, const int &line, const char *condition)
report violation of assertion
Definition: error.cc:128