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