AFF --- A container for numbers (array) by Friederich and Forbriger.
error.cc
Go to the documentation of this file.
1 
40 #define AFF_ERROR_CC_VERSION \
41  "AFF_ERROR_CC V1.2"
42 
43 #include <iostream>
44 #include <aff/lib/error.h>
45 
46 using std::cerr;
47 using std::endl;
48 
49 namespace aff {
50 
53 
56  Mmessage(0), Mfile(0), Mline(0), Mcondition(0)
57  { if (Mreport_on_construct) { report(); } }
58 
60  Exception::Exception(const char* message):
61  Mmessage(message), Mfile(0), Mline(0), Mcondition(0)
62  { if (Mreport_on_construct) { report(); } }
63 
65  Exception::Exception(const char* message,
66  const char* condition):
67  Mmessage(message), Mfile(0), Mline(0), Mcondition(condition)
68  { if (Mreport_on_construct) { report(); } }
69 
71  Exception::Exception(const char* message,
72  const char* file,
73  const int& line):
74  Mmessage(message), Mfile(file), Mline(line), Mcondition(0)
75  { if (Mreport_on_construct) { report(); } }
76 
78  Exception::Exception(const char* message,
79  const char* file,
80  const int& line,
81  const char* condition):
82  Mmessage(message), Mfile(file), Mline(line), Mcondition(condition)
83  { if (Mreport_on_construct) { report(); } }
84 
87  {
89  }
90 
93  {
95  }
96 
98  void Exception::report() const
99  {
100  base_report();
101  }
102 
105  {
106  cerr << "Exception report:" << endl;
107  if (Mmessage==0)
108  {
109  cerr << " No message" << endl;
110  }
111  else
112  {
113  cerr << " message: " << Mmessage << endl;
114  }
115  if (Mfile!=0)
116  {
117  cerr << " triggered in \"" << Mfile << "\" at line #" << Mline << endl;
118  }
119  if (Mcondition!=0)
120  {
121  cerr << " by condition:" << endl
122  << " \"" << Mcondition << "\"" << endl;
123  }
124  }
125 
126  /*======================================================================*/
127  // AllocException code
128 
131  Exception("ERROR: memory allocation failed!"), Mn(n), Msize(size) { }
132 
135  {
136  base_report();
137  std::cout << " You requested " << Mn << " memory locations of "
138  << Msize << " Bytes size." << std::endl;
139  }
140 
141 } // namespace aff
142 
143 /* ----- END OF error.cc ----- */
Root namespace of library.
Definition: array.h:148
AllocException(const Tsize &n, const Tsize &size)
take number of requested elements and their size
Definition: error.cc:130
const char * Mmessage
pointer to message string
Definition: error.h:108
Exception()
Creates exception with no explaning comments.
Definition: error.cc:55
virtual void report() const
Screen report.
Definition: error.cc:98
static bool Mreport_on_construct
Shall we print to cerr at construction time?
Definition: error.h:106
virtual void report() const
Screen report.
Definition: error.cc:134
static void report_on_construct()
Issue a screen report on construction of exception.
Definition: error.cc:86
exceptions and error handling macros (prototypes)
Base class for exceptions.
Definition: error.h:74
const int & Mline
pointer to line number in source file
Definition: error.h:112
const char * Mcondition
pointer to assertion condition text string
Definition: error.h:114
const char * Mfile
pointer to file name string
Definition: error.h:110
Tsize Mn
members to remember
Definition: error.h:136
static void dont_report_on_construct()
Issue NO screen report on construction of exception.
Definition: error.cc:92
void base_report() const
Screen report.
Definition: error.cc:104
size_t Tsize
Type to hold the size of an array dimension.
Definition: types.h:51