Jpp 21.0.0-rc.1
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#include <functional>
10
11
12/**
13 * \file
14 * Exceptions.
15 * \author mdejong
16 */
17namespace JLANG {}
18namespace JPP { using namespace JLANG; }
19
20namespace JLANG {
21
22 /**
23 * General exception
24 */
25 class JException : public std::exception {
26 public:
27 /**
28 * Get date and time [UTC].
29 *
30 * \return date and time [UTC]
31 */
32 static std::string getDateAndTime()
33 {
34 using namespace std;
35
36 time_t result = time(NULL);
37
38 return asctime(gmtime(&result));
39 }
40
41
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() override
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 */
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 */
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 */
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#ifndef MAKE_EXCEPTION
688#define MAKE_EXCEPTION(JException_t, A) std::invoke( [&]() { std::ostringstream out; out << JLANG::JException::getDateAndTime() << ' ' << __FILE__ << ':' << __LINE__ << std::endl << A; return JException_t(out.str()); } )
689#endif
690
691
692/**
693 * Marco for throwing exception with std::ostream compatible message.
694 *
695 * \param JException_t exception
696 * \param A message
697 */
698#ifndef THROW
699#define THROW(JException_t, A) do { throw MAKE_EXCEPTION(JException_t, A); } while(0)
700#endif
701
702#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:25
static std::string getDateAndTime()
Get date and time [UTC].
Definition JException.hh:32
friend std::ostream & operator<<(std::ostream &out, const JException &exception)
Print error message of JException.
Definition JException.hh:77
const std::string buffer
Definition JException.hh:83
~JException()
Destructor.
Definition JException.hh:56
virtual const char * what() const override
Get error message.
Definition JException.hh:65
JException(const std::string &error)
Constructor.
Definition JException.hh:47
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.
Definition JException.hh:92
JIndexOutOfRange(const std::string &error)
Constructor.
Definition JException.hh:99
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).