SERIAL++ library: simple serial port access
error.cc
Go to the documentation of this file.
1 
36 #define TF_ERROR_CC_VERSION \
37  "TF_ERROR_CC V1.0 "
38 #define TF_ERROR_CC_CVSID \
39  "$Id$"
40 
41 
42 #include <iostream>
43 #include <serialxx/error.h>
44 
45 using std::cerr;
46 using std::endl;
47 
48 namespace serialport {
49 
52 
55  Mmessage(0), Mfile(0), Mline(0), Mcondition(0)
56  { if (Mreport_on_construct) { report(); } }
57 
59  Exception::Exception(const char* message):
60  Mmessage(message), Mfile(0), Mline(0), Mcondition(0)
61  { if (Mreport_on_construct) { report(); } }
62 
64  Exception::Exception(const char* message,
65  const char* condition):
66  Mmessage(message), Mfile(0), Mline(0), Mcondition(condition)
67  { if (Mreport_on_construct) { report(); } }
68 
70  Exception::Exception(const char* message,
71  const char* file,
72  const int& line):
73  Mmessage(message), Mfile(file), Mline(line), Mcondition(0)
74  { if (Mreport_on_construct) { report(); } }
75 
77  Exception::Exception(const char* message,
78  const char* file,
79  const int& line,
80  const char* condition):
81  Mmessage(message), Mfile(file), Mline(line), Mcondition(condition)
82  { if (Mreport_on_construct) { report(); } }
83 
86  {
88  }
89 
92  {
94  }
95 
97  void Exception::report() const
98  {
99  base_report();
100  }
101 
104  {
105  cerr << "Exception report:" << endl;
106  if (Mmessage==0)
107  {
108  cerr << " No message" << endl;
109  }
110  else
111  {
112  cerr << " message: " << Mmessage << endl;
113  }
114  if (Mfile!=0)
115  {
116  cerr << " triggered in \"" << Mfile << "\" at line #" << Mline << endl;
117  }
118  if (Mcondition!=0)
119  {
120  cerr << " by condition:" << endl
121  << " \"" << Mcondition << "\"" << endl;
122  }
123  }
124 
125  /*----------------------------------------------------------------------*/
126 
128  void report_violation(const char* message,
129  const char* file,
130  const int& line,
131  const char* condition)
132  {
133  std::cerr << std::endl;
134  std::cerr << "VIOLATION of condition: " << condition << std::endl;
135  std::cerr << "* in " << file << " at line " << line << std::endl;
136  std::cerr << "* message: " << message << std::endl;
137  }
138 
139 } // namespace serialport
140 
141 /* ----- END OF error.cc ----- */
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
error handling code for serial port access (prototypes)
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