Jpp
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JException.hh
Go to the documentation of this file.
1 #ifndef __JLANG__JEXCEPTION__
2 #define __JLANG__JEXCEPTION__
3 
4 #include <exception>
5 #include <string>
6 #include <ostream>
7 #include <sstream>
8 
9 
10 /**
11  * \file
12  * Exceptions.
13  * \author mdejong
14  */
15 namespace JLANG {}
16 namespace JPP { using namespace JLANG; }
17 
18 namespace JLANG {
19 
20  /**
21  * Get output stream for conversion of exception.
22  *
23  * Note that the ostream is emptied before use.
24  *
25  * \return ostream
26  */
27  inline std::ostream& getOstream()
28  {
29  static std::ostringstream buffer;
30 
31  buffer.str("");
32 
33  return buffer;
34  }
35 
36 
37  /**
38  * General exception
39  */
40  class JException : public std::exception {
41  public:
42  /**
43  * Constructor.
44  *
45  * \param error error message
46  */
47  JException(const std::string& error) :
48  std::exception(),
49  buffer(error)
50  {}
51 
52 
53  /**
54  * Destructor.
55  */
56  ~JException() throw()
57  {}
58 
59 
60  /**
61  * Get error message.
62  *
63  * \return error message
64  */
65  virtual const char* what() const throw()
66  {
67  return buffer.c_str();
68  }
69 
70 
71  /**
72  * Print error message of JException.
73  *
74  * \param out output stream
75  * \param exception exception
76  */
77  friend inline std::ostream& operator<<(std::ostream& out, const JException& exception)
78  {
79  return out << exception.what();
80  }
81 
82  private:
83  const std::string buffer;
84  };
85 
86 
87  /**
88  * Exception for accessing an index in a collection that is outside of its range.
89  */
91  public JException
92  {
93  public:
94  /**
95  * Constructor.
96  *
97  * \param error error message
98  */
99  JIndexOutOfRange(const std::string& error) :
100  JException(error)
101  {}
102  };
103 
104 
105  /**
106  * Exception for accessing an invalid pointer.
107  */
109  public JException
110  {
111  public:
112  /**
113  * Constructor.
114  *
115  * \param error error message
116  */
117  JPointerException(const std::string& error) :
118  JException(error)
119  {}
120  };
121 
122 
123  /**
124  * Exception for an empty collection.
125  */
127  public JException
128  {
129  public:
130  /**
131  * Constructor.
132  *
133  * \param error error message
134  */
135  JEmptyCollection(const std::string& error) :
136  JException(error)
137  {}
138  };
139 
140 
141  /**
142  * Exception for accessing a value in a collection that is outside of its range.
143  */
145  public JException
146  {
147  public:
148  /**
149  * Constructor.
150  *
151  * \param error error message
152  */
153  JValueOutOfRange(const std::string& error) :
154  JException(error)
155  {}
156  };
157 
158 
159  /**
160  * Exception for parsing value.
161  */
162  class JParseError :
163  public JException
164  {
165  public:
166  /**
167  * Constructor.
168  *
169  * \param error error message
170  */
171  JParseError(const std::string& error) :
172  JException(error)
173  {}
174  };
175 
176 
177  /**
178  * Exception for missing value.
179  */
180  class JNoValue :
181  public JException
182  {
183  public:
184  /**
185  * Constructor.
186  *
187  * \param error error message
188  */
189  JNoValue(const std::string& error) :
190  JException(error)
191  {}
192  };
193 
194 
195  /**
196  * Exception for null pointer operation.
197  */
199  public JException
200  {
201  public:
202  /**
203  * Constructor.
204  *
205  * \param error error message
206  */
207  JNullPointerException(const std::string& error) :
208  JException(error)
209  {}
210  };
211 
212 
213  /**
214  * Exception for cast operation.
215  */
217  public JException
218  {
219  public:
220  /**
221  * Constructor.
222  *
223  * \param error error message
224  */
225  JCastException(const std::string& error) :
226  JException(error)
227  {}
228  };
229 
230 
231  /**
232  * Exception for numerical precision error.
233  */
235  public JException
236  {
237  public:
238  /**
239  * Constructor.
240  *
241  * \param error error message
242  */
243  JNumericalPrecision(const std::string& error) :
244  JException(error)
245  {}
246  };
247 
248 
249  /**
250  * Exception for division by zero.
251  */
253  public JException
254  {
255  public:
256  /**
257  * Constructor.
258  *
259  * \param error error message
260  */
261  JDivisionByZero(const std::string& error) :
262  JException(error)
263  {}
264  };
265 
266 
267  /**
268  * Exception for failure of memory allocation.
269  */
271  public JException
272  {
273  public:
274  /**
275  * Constructor.
276  *
277  * \param error error message
278  */
279  JMallocException(const std::string& error) :
280  JException(error)
281  {}
282  };
283 
284 
285  /**
286  * Exception for failure of memory allocation.
287  */
288  class JNewException :
289  public JException
290  {
291  public:
292  /**
293  * Constructor.
294  *
295  * \param error error message
296  */
297  JNewException(const std::string& error) :
298  JException(error)
299  {}
300  };
301 
302 
303  /**
304  * Exception for I/O.
305  */
306  class JIOException :
307  public JException
308  {
309  public:
310  /**
311  * Constructor.
312  *
313  * \param error error message
314  */
315  JIOException(const std::string& error) :
316  JException(error)
317  {}
318  };
319 
320 
321  /**
322  * Exception for opening of file.
323  */
325  public JException
326  {
327  public:
328  /**
329  * Constructor.
330  *
331  * \param error error message
332  */
333  JFileOpenException(const std::string& error) :
334  JException(error)
335  {}
336  };
337 
338 
339  /**
340  * Exception for reading of file.
341  */
343  public JException
344  {
345  public:
346  /**
347  * Constructor.
348  *
349  * \param error error message
350  */
351  JFileReadException(const std::string& error) :
352  JException(error)
353  {}
354  };
355 
356 
357  /**
358  * Exception for end of file.
359  */
360  class JEndOfFile :
361  public JException
362  {
363  public:
364  /**
365  * Constructor.
366  *
367  * \param error error message
368  */
369  JEndOfFile(const std::string& error) :
370  JException(error)
371  {}
372  };
373 
374 
375  /**
376  * Exception for opening of pipe.
377  */
379  public JException
380  {
381  public:
382  /**
383  * Constructor.
384  *
385  * \param error error message
386  */
387  JPipeOpenException(const std::string& error) :
388  JException(error)
389  {}
390  };
391 
392 
393  /**
394  * Exception for select call.
395  */
397  public JException
398  {
399  public:
400  /**
401  * Constructor.
402  *
403  * \param error error message
404  */
405  JSelectException(const std::string& error) :
406  JException(error)
407  {}
408  };
409 
410 
411  /**
412  * Exception for socket.
413  */
415  public JException
416  {
417  public:
418  /**
419  * Constructor.
420  *
421  * \param error error message
422  */
423  JSocketException(const std::string& error) :
424  JException(error)
425  {}
426  };
427 
428 
429  /**
430  * Exception for ControlHost.
431  */
433  public JException
434  {
435  public:
436  /**
437  * Constructor.
438  *
439  * \param error error message
440  */
441  JControlHostException(const std::string& error) :
442  JException(error)
443  {}
444  };
445 
446 
447  /**
448  * Exception for socket channel.
449  */
451  public JException
452  {
453  public:
454  /**
455  * Constructor.
456  *
457  * \param error error message
458  */
459  JSocketChannelException(const std::string& error) :
460  JException(error)
461  {}
462  };
463 
464 
465  /**
466  * Exception for creation of fork.
467  */
468  class JForkException :
469  public JException
470  {
471  public:
472  /**
473  * Constructor.
474  *
475  * \param error error message
476  */
477  JForkException(const std::string& error) :
478  JException(error)
479  {}
480  };
481 
482 
483  /**
484  * Exception for system call.
485  */
487  public JException
488  {
489  public:
490  /**
491  * Constructor.
492  *
493  * \param error error message
494  */
495  JSystemException(const std::string& error) :
496  JException(error)
497  {}
498  };
499 
500 
501  /**
502  * Exception when parsing a value.
503  */
505  public JException
506  {
507  public:
508  /**
509  * Constructor.
510  *
511  * \param error error message
512  */
513  JParserException(const std::string& error) :
514  JException(error)
515  {}
516  };
517 
518 
519  /**
520  * Exception when parsing a value.
521  */
523  public JException
524  {
525  public:
526  /**
527  * Constructor.
528  *
529  * \param error error message
530  */
531  JPropertiesException(const std::string& error) :
532  JException(error)
533  {}
534  };
535 
536 
537  /**
538  * Exception for missing entry in dictionary.
539  */
541  public JException
542  {
543  public:
544  /**
545  * Constructor.
546  *
547  * \param error error message
548  */
549  JDictionaryEntryNotFound(const std::string& error) :
550  JException(error)
551  {}
552  };
553 
554 
555  /**
556  * Exception for duplicate entry in dictionary.
557  */
559  public JException
560  {
561  public:
562  /**
563  * Constructor.
564  *
565  * \param error error message
566  */
567  JDictionaryDuplicateEntry(const std::string& error) :
568  JException(error)
569  {}
570  };
571 
572 
573  /**
574  * Run time exception.
575  */
577  public JException
578  {
579  public:
580  /**
581  * Constructor.
582  *
583  * \param error error message
584  */
585  JRunTimeException(const std::string& error) :
586  JException(error)
587  {}
588  };
589 
590 
591  /**
592  * Exception for absence of type information.
593  */
595  public JException
596  {
597  public:
598  /**
599  * Constructor.
600  *
601  * \param error error message
602  */
603  JTypeInformationException(const std::string& error) :
604  JException(error)
605  {}
606  };
607 
608 
609  /**
610  * Protocol exception.
611  */
613  public JException
614  {
615  public:
616  /**
617  * Constructor.
618  *
619  * \param error error message
620  */
621  JProtocolException(const std::string& error) :
622  JException(error)
623  {}
624  };
625 }
626 
627 /**
628  * Marco for throwing exception with std::ostream compatible message.
629  *
630  * \param JException_t exception
631  * \param A message
632  */
633 #define THROW(JException_t, A) do { throw JException_t(static_cast<std::ostringstream&>(JLANG::getOstream() << __FILE__ << ':' << __LINE__ << std::endl << A).str()); } while(0)
634 
635 #endif
Exception for opening of file.
Definition: JException.hh:324
JSystemException(const std::string &error)
Constructor.
Definition: JException.hh:495
Exception for failure of memory allocation.
Definition: JException.hh:288
General exception.
Definition: JException.hh:40
Exception for reading of file.
Definition: JException.hh:342
friend std::ostream & operator<<(std::ostream &out, const JException &exception)
Print error message of JException.
Definition: JException.hh:77
Exception for absence of type information.
Definition: JException.hh:594
JMallocException(const std::string &error)
Constructor.
Definition: JException.hh:279
JPropertiesException(const std::string &error)
Constructor.
Definition: JException.hh:531
JEmptyCollection(const std::string &error)
Constructor.
Definition: JException.hh:135
Exception for accessing an invalid pointer.
Definition: JException.hh:108
JNewException(const std::string &error)
Constructor.
Definition: JException.hh:297
JTypeInformationException(const std::string &error)
Constructor.
Definition: JException.hh:603
Exception for socket channel.
Definition: JException.hh:450
~JException()
Destructor.
Definition: JException.hh:56
JProtocolException(const std::string &error)
Constructor.
Definition: JException.hh:621
JControlHostException(const std::string &error)
Constructor.
Definition: JException.hh:441
JEndOfFile(const std::string &error)
Constructor.
Definition: JException.hh:369
Exception when parsing a value.
Definition: JException.hh:522
JSocketChannelException(const std::string &error)
Constructor.
Definition: JException.hh:459
JSelectException(const std::string &error)
Constructor.
Definition: JException.hh:405
JPointerException(const std::string &error)
Constructor.
Definition: JException.hh:117
JParserException(const std::string &error)
Constructor.
Definition: JException.hh:513
JIndexOutOfRange(const std::string &error)
Constructor.
Definition: JException.hh:99
JParseError(const std::string &error)
Constructor.
Definition: JException.hh:171
JForkException(const std::string &error)
Constructor.
Definition: JException.hh:477
Exception for select call.
Definition: JException.hh:396
JDictionaryDuplicateEntry(const std::string &error)
Constructor.
Definition: JException.hh:567
Exception for missing value.
Definition: JException.hh:180
Run time exception.
Definition: JException.hh:576
Exception for null pointer operation.
Definition: JException.hh:198
Exception for opening of pipe.
Definition: JException.hh:378
Exception for missing entry in dictionary.
Definition: JException.hh:540
Exception for duplicate entry in dictionary.
Definition: JException.hh:558
Exception for failure of memory allocation.
Definition: JException.hh:270
JDictionaryEntryNotFound(const std::string &error)
Constructor.
Definition: JException.hh:549
Exception for creation of fork.
Definition: JException.hh:468
std::ostream & getOstream()
Get output stream for conversion to std::string or C-string.
Definition: JPrint.hh:51
JNumericalPrecision(const std::string &error)
Constructor.
Definition: JException.hh:243
Exception for ControlHost.
Definition: JException.hh:432
JValueOutOfRange(const std::string &error)
Constructor.
Definition: JException.hh:153
JIOException(const std::string &error)
Constructor.
Definition: JException.hh:315
Exception when parsing a value.
Definition: JException.hh:504
JDivisionByZero(const std::string &error)
Constructor.
Definition: JException.hh:261
Protocol exception.
Definition: JException.hh:612
Exception for cast operation.
Definition: JException.hh:216
const std::string buffer
Definition: JException.hh:83
Exception for numerical precision error.
Definition: JException.hh:234
JFileOpenException(const std::string &error)
Constructor.
Definition: JException.hh:333
JSocketException(const std::string &error)
Constructor.
Definition: JException.hh:423
Exception for division by zero.
Definition: JException.hh:252
Exception for socket.
Definition: JException.hh:414
Exception for system call.
Definition: JException.hh:486
Exception for parsing value.
Definition: JException.hh:162
Exception for an empty collection.
Definition: JException.hh:126
JFileReadException(const std::string &error)
Constructor.
Definition: JException.hh:351
JRunTimeException(const std::string &error)
Constructor.
Definition: JException.hh:585
Exception for accessing a value in a collection that is outside of its range.
Definition: JException.hh:144
JNoValue(const std::string &error)
Constructor.
Definition: JException.hh:189
Exception for accessing an index in a collection that is outside of its range.
Definition: JException.hh:90
virtual const char * what() const
Get error message.
Definition: JException.hh:65
Exception for end of file.
Definition: JException.hh:360
JNullPointerException(const std::string &error)
Constructor.
Definition: JException.hh:207
JCastException(const std::string &error)
Constructor.
Definition: JException.hh:225
JPipeOpenException(const std::string &error)
Constructor.
Definition: JException.hh:387
JException(const std::string &error)
Constructor.
Definition: JException.hh:47
Exception for I/O.
Definition: JException.hh:306