Jpp
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 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 reading of file.
359  */
361  public JException
362  {
363  public:
364  /**
365  * Constructor.
366  *
367  * \param error error message
368  */
369  JFileReadException(const std::string& error) :
370  JException(error)
371  {}
372  };
373 
374 
375  /**
376  * Exception for end of file.
377  */
378  class JEndOfFile :
379  public JException
380  {
381  public:
382  /**
383  * Constructor.
384  *
385  * \param error error message
386  */
387  JEndOfFile(const std::string& error) :
388  JException(error)
389  {}
390  };
391 
392 
393  /**
394  * Exception for opening of pipe.
395  */
397  public JException
398  {
399  public:
400  /**
401  * Constructor.
402  *
403  * \param error error message
404  */
405  JPipeOpenException(const std::string& error) :
406  JException(error)
407  {}
408  };
409 
410 
411  /**
412  * Exception for select call.
413  */
415  public JException
416  {
417  public:
418  /**
419  * Constructor.
420  *
421  * \param error error message
422  */
423  JSelectException(const std::string& error) :
424  JException(error)
425  {}
426  };
427 
428 
429  /**
430  * Exception for socket.
431  */
433  public JException
434  {
435  public:
436  /**
437  * Constructor.
438  *
439  * \param error error message
440  */
441  JSocketException(const std::string& error) :
442  JException(error)
443  {}
444  };
445 
446 
447  /**
448  * Exception for ControlHost.
449  */
451  public JException
452  {
453  public:
454  /**
455  * Constructor.
456  *
457  * \param error error message
458  */
459  JControlHostException(const std::string& error) :
460  JException(error)
461  {}
462  };
463 
464 
465  /**
466  * Exception for socket channel.
467  */
469  public JException
470  {
471  public:
472  /**
473  * Constructor.
474  *
475  * \param error error message
476  */
477  JSocketChannelException(const std::string& error) :
478  JException(error)
479  {}
480  };
481 
482 
483  /**
484  * Exception for creation of fork.
485  */
486  class JForkException :
487  public JException
488  {
489  public:
490  /**
491  * Constructor.
492  *
493  * \param error error message
494  */
495  JForkException(const std::string& error) :
496  JException(error)
497  {}
498  };
499 
500 
501  /**
502  * Exception for system call.
503  */
505  public JException
506  {
507  public:
508  /**
509  * Constructor.
510  *
511  * \param error error message
512  */
513  JSystemException(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  JParserException(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  JPropertiesException(const std::string& error) :
550  JException(error)
551  {}
552  };
553 
554 
555  /**
556  * Exception for missing entry in dictionary.
557  */
559  public JException
560  {
561  public:
562  /**
563  * Constructor.
564  *
565  * \param error error message
566  */
567  JDictionaryEntryNotFound(const std::string& error) :
568  JException(error)
569  {}
570  };
571 
572 
573  /**
574  * Exception for duplicate entry in dictionary.
575  */
577  public JException
578  {
579  public:
580  /**
581  * Constructor.
582  *
583  * \param error error message
584  */
585  JDictionaryDuplicateEntry(const std::string& error) :
586  JException(error)
587  {}
588  };
589 
590 
591  /**
592  * Run time exception.
593  */
595  public JException
596  {
597  public:
598  /**
599  * Constructor.
600  *
601  * \param error error message
602  */
603  JRunTimeException(const std::string& error) :
604  JException(error)
605  {}
606  };
607 
608 
609  /**
610  * Exception for absence of type information.
611  */
613  public JException
614  {
615  public:
616  /**
617  * Constructor.
618  *
619  * \param error error message
620  */
621  JTypeInformationException(const std::string& error) :
622  JException(error)
623  {}
624  };
625 
626 
627  /**
628  * Protocol exception.
629  */
631  public JException
632  {
633  public:
634  /**
635  * Constructor.
636  *
637  * \param error error message
638  */
639  JProtocolException(const std::string& error) :
640  JException(error)
641  {}
642  };
643 
644 
645  /**
646  * Database exception.
647  */
649  public JException
650  {
651  public:
652  /**
653  * Constructor.
654  *
655  * \param error error message
656  */
657  JDatabaseException(const std::string& error) :
658  JException(error)
659  {}
660  };
661 }
662 
663 /**
664  * Marco for throwing exception with std::ostream compatible message.
665  *
666  * \param JException_t exception
667  * \param A message
668  */
669 #define THROW(JException_t, A) do { throw JException_t(static_cast<std::ostringstream&>(JLANG::getOstream() << __FILE__ << ':' << __LINE__ << std::endl << A).str()); } while(0)
670 
671 #endif
JLANG::JNoValue::JNoValue
JNoValue(const std::string &error)
Constructor.
Definition: JException.hh:207
JLANG::JMallocException::JMallocException
JMallocException(const std::string &error)
Constructor.
Definition: JException.hh:297
JLANG::JDatabaseException
Database exception.
Definition: JException.hh:648
JLANG::JSocketException::JSocketException
JSocketException(const std::string &error)
Constructor.
Definition: JException.hh:441
JLANG::JIndexOutOfRange
Exception for accessing an index in a collection that is outside of its range.
Definition: JException.hh:90
JLANG::JPropertiesException
Exception when parsing a value.
Definition: JException.hh:540
JLANG::JSelectException::JSelectException
JSelectException(const std::string &error)
Constructor.
Definition: JException.hh:423
JLANG::JPropertiesException::JPropertiesException
JPropertiesException(const std::string &error)
Constructor.
Definition: JException.hh:549
JLANG::JException::operator<<
friend std::ostream & operator<<(std::ostream &out, const JException &exception)
Print error message of JException.
Definition: JException.hh:77
JLANG::JIOException::JIOException
JIOException(const std::string &error)
Constructor.
Definition: JException.hh:333
JLANG::JControlHostException::JControlHostException
JControlHostException(const std::string &error)
Constructor.
Definition: JException.hh:459
JLANG::JFileReadException::JFileReadException
JFileReadException(const std::string &error)
Constructor.
Definition: JException.hh:369
JLANG::JDatabaseException::JDatabaseException
JDatabaseException(const std::string &error)
Constructor.
Definition: JException.hh:657
JLANG::JFileReadException
Exception for reading of file.
Definition: JException.hh:360
JLANG::JEndOfFile::JEndOfFile
JEndOfFile(const std::string &error)
Constructor.
Definition: JException.hh:387
JLANG::JDivisionByZero::JDivisionByZero
JDivisionByZero(const std::string &error)
Constructor.
Definition: JException.hh:279
JLANG::JParseError::JParseError
JParseError(const std::string &error)
Constructor.
Definition: JException.hh:189
JLANG::JNoValue
Exception for missing value.
Definition: JException.hh:198
JLANG::JControlHostException
Exception for ControlHost.
Definition: JException.hh:450
JLANG::JParserException::JParserException
JParserException(const std::string &error)
Constructor.
Definition: JException.hh:531
JLANG::JEmptyCollection
Exception for an empty collection.
Definition: JException.hh:144
JLANG::JFileOpenException
Exception for opening of file.
Definition: JException.hh:342
JLANG::JException::JException
JException(const std::string &error)
Constructor.
Definition: JException.hh:47
JLANG::JCastException
Exception for cast operation.
Definition: JException.hh:234
JLANG::JSystemException
Exception for system call.
Definition: JException.hh:504
JLANG::JNullPointerException
Exception for null pointer operation.
Definition: JException.hh:216
JLANG::JValueOutOfRange::JValueOutOfRange
JValueOutOfRange(const std::string &error)
Constructor.
Definition: JException.hh:171
JLANG::JTypeInformationException::JTypeInformationException
JTypeInformationException(const std::string &error)
Constructor.
Definition: JException.hh:621
JLANG::JSocketException
Exception for socket.
Definition: JException.hh:432
JLANG::JSocketChannelException::JSocketChannelException
JSocketChannelException(const std::string &error)
Constructor.
Definition: JException.hh:477
JLANG::JNullPointerException::JNullPointerException
JNullPointerException(const std::string &error)
Constructor.
Definition: JException.hh:225
JLANG::JException::buffer
const std::string buffer
Definition: JException.hh:83
JLANG::JSelectException
Exception for select call.
Definition: JException.hh:414
JLANG::JForkException::JForkException
JForkException(const std::string &error)
Constructor.
Definition: JException.hh:495
JLANG::JException::~JException
~JException()
Destructor.
Definition: JException.hh:56
JPP
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).
Definition: JAAnetToolkit.hh:37
JLANG::JPipeOpenException
Exception for opening of pipe.
Definition: JException.hh:396
JLANG::JPointerException
Exception for accessing an invalid pointer.
Definition: JException.hh:108
JLANG::JSystemException::JSystemException
JSystemException(const std::string &error)
Constructor.
Definition: JException.hh:513
JLANG::JParserException
Exception when parsing a value.
Definition: JException.hh:522
JLANG::JMallocException
Exception for failure of memory allocation.
Definition: JException.hh:288
JLANG::JRunTimeException::JRunTimeException
JRunTimeException(const std::string &error)
Constructor.
Definition: JException.hh:603
JLANG::JFunctionalException::JFunctionalException
JFunctionalException(const std::string &error)
Constructor.
Definition: JException.hh:135
JLANG::JForkException
Exception for creation of fork.
Definition: JException.hh:486
JLANG::JDictionaryDuplicateEntry::JDictionaryDuplicateEntry
JDictionaryDuplicateEntry(const std::string &error)
Constructor.
Definition: JException.hh:585
JLANG::JDictionaryEntryNotFound
Exception for missing entry in dictionary.
Definition: JException.hh:558
JLANG::JProtocolException
Protocol exception.
Definition: JException.hh:630
JLANG::JValueOutOfRange
Exception for accessing a value in a collection that is outside of its range.
Definition: JException.hh:162
JLANG::JIndexOutOfRange::JIndexOutOfRange
JIndexOutOfRange(const std::string &error)
Constructor.
Definition: JException.hh:99
JLANG::JFunctionalException
Exception for a functional operation.
Definition: JException.hh:126
JLANG::getOstream
std::ostream & getOstream()
Get output stream for conversion of exception.
Definition: JException.hh:27
JLANG::JProtocolException::JProtocolException
JProtocolException(const std::string &error)
Constructor.
Definition: JException.hh:639
JLANG::JParseError
Exception for parsing value.
Definition: JException.hh:180
JLANG::JEndOfFile
Exception for end of file.
Definition: JException.hh:378
JLANG::JDictionaryDuplicateEntry
Exception for duplicate entry in dictionary.
Definition: JException.hh:576
std
Definition: jaanetDictionary.h:36
JLANG::JNewException::JNewException
JNewException(const std::string &error)
Constructor.
Definition: JException.hh:315
JLANG::JRunTimeException
Run time exception.
Definition: JException.hh:594
JLANG::JSocketChannelException
Exception for socket channel.
Definition: JException.hh:468
JLANG::JDivisionByZero
Exception for division by zero.
Definition: JException.hh:270
JLANG::JDictionaryEntryNotFound::JDictionaryEntryNotFound
JDictionaryEntryNotFound(const std::string &error)
Constructor.
Definition: JException.hh:567
JLANG::JPipeOpenException::JPipeOpenException
JPipeOpenException(const std::string &error)
Constructor.
Definition: JException.hh:405
JLANG::JPointerException::JPointerException
JPointerException(const std::string &error)
Constructor.
Definition: JException.hh:117
JLANG::JNumericalPrecision::JNumericalPrecision
JNumericalPrecision(const std::string &error)
Constructor.
Definition: JException.hh:261
JLANG::JTypeInformationException
Exception for absence of type information.
Definition: JException.hh:612
JLANG::JException::what
virtual const char * what() const
Get error message.
Definition: JException.hh:65
JLANG::JFileOpenException::JFileOpenException
JFileOpenException(const std::string &error)
Constructor.
Definition: JException.hh:351
JLANG::JIOException
Exception for I/O.
Definition: JException.hh:324
JLANG::JCastException::JCastException
JCastException(const std::string &error)
Constructor.
Definition: JException.hh:243
JLANG
Auxiliary classes and methods for language specific functionality.
Definition: JAbstractClass.hh:10
JLANG::JNumericalPrecision
Exception for numerical precision error.
Definition: JException.hh:252
JLANG::JException
General exception.
Definition: JException.hh:40
JLANG::JNewException
Exception for failure of memory allocation.
Definition: JException.hh:306
JLANG::JEmptyCollection::JEmptyCollection
JEmptyCollection(const std::string &error)
Constructor.
Definition: JException.hh:153