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