Fortran SFF API to data I/O streams in C++
error.cc
Go to the documentation of this file.
1 
35 #define FAPIDXX_ERROR_CC_VERSION \
36  "FAPIDXX_ERROR_CC V1.0"
37 
38 #include <iostream>
39 #include <fapidxx/error.h>
40 
41 using std::cerr;
42 using std::endl;
43 
44 namespace fapidxx {
45 namespace error {
46 
49 
52  Mmessage(NULL), Mfile(NULL), Mline(0), Mcondition(NULL)
53  { if (Mreport_on_construct) { report(); } }
54 
56  Exception::Exception(const char* message):
57  Mmessage(message), Mfile(NULL), Mline(0), Mcondition(NULL)
58  { if (Mreport_on_construct) { report(); } }
59 
61  Exception::Exception(const char* message,
62  const char* condition):
63  Mmessage(message), Mfile(NULL), Mline(0), Mcondition(condition)
64  { if (Mreport_on_construct) { report(); } }
65 
67  Exception::Exception(const char* message,
68  const char* file,
69  const int& line):
70  Mmessage(message), Mfile(file), Mline(line), Mcondition(NULL)
71  { if (Mreport_on_construct) { report(); } }
72 
74  Exception::Exception(const char* message,
75  const char* file,
76  const int& line,
77  const char* condition):
78  Mmessage(message), Mfile(file), Mline(line), Mcondition(condition)
79  { if (Mreport_on_construct) { report(); } }
80 
83  {
85  }
86 
89  {
91  }
92 
94  void Exception::report() const
95  {
96  base_report();
97  }
98 
101  {
102  std::cout.flush();
103  cerr << "Exception report:" << endl;
104  if (Mmessage==NULL)
105  {
106  cerr << " No message" << endl;
107  }
108  else
109  {
110  cerr << " message: " << Mmessage << endl;
111  }
112  if (Mfile!=NULL)
113  {
114  cerr << " triggered in \"" << Mfile << "\" at line #" << Mline << endl;
115  }
116  if (Mcondition!=NULL)
117  {
118  cerr << " by test condition:" << endl
119  << " \"" << Mcondition << "\"" << endl;
120  }
121  cerr.flush();
122  }
123 
124  /*----------------------------------------------------------------------*/
125 
127  FUException::FUException(const int& unit,
128  const char* message,
129  const char* file,
130  const int& line,
131  const char* condition):
132  Exception(message, file, line, condition), Munit(unit) { }
133 
134  /*----------------------------------------------------------------------*/
135 
137  void FUException::report() const
138  {
139  this->Exception::report();
140  cerr << " Selected file unit: " << Munit << endl;
141  cerr.flush();
142  }
143 
144 } // namespace error
145 } // namespace fapidxx
146 
147 /* ----- END OF error.cc ----- */
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
exceptions and error handling macros (prototypes)
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