Jpp 19.3.0-rc.1
the software that should make you happy
Loading...
Searching...
No Matches
JThrow.hh
Go to the documentation of this file.
1#ifndef __JLANG__JTHROW__
2#define __JLANG__JTHROW__
3
4#include <iostream>
5
6#include "JLang/JException.hh"
7
8
9/**
10 * \file
11 *
12 * Exception handling.
13 * \author mdejong
14 */
15namespace JLANG {}
16namespace JPP { using namespace JLANG; }
17
18namespace JLANG {
19
20 /**
21 * Auxiliary base class for controling the throwing of exceptions.
22 * The template class refers to the throwing object.
23 */
24 template<class T>
25 class JThrow {
26 protected:
27
28 static bool do_throw; //!< throw option
29
30
31 public:
32 /**
33 * Enable/disable throw option.
34 *
35 * \param option true enable; false disable
36 */
37 static void Throw(const bool option)
38 {
39 do_throw = option;
40 }
41
42
43 /**
44 * Throw exception or return error.
45 *
46 * \param error exception
47 * \param value return code
48 * \return return code
49 */
50 template<class JException_t>
51 static int Throw(const JException_t& error, const int value = -1)
52 {
53 using namespace std;
54
55 if (do_throw) {
56 throw error;
57 }
58
59 cerr << error.what() << endl;
60
61 return value;
62 }
63 };
64
65
66 /**
67 * Set default throw option to <tt>true</tt>.
68 */
69 template<class T>
70 bool JThrow<T>::do_throw = true;
71}
72
73#endif
Exceptions.
Auxiliary base class for controling the throwing of exceptions.
Definition JThrow.hh:25
static int Throw(const JException_t &error, const int value=-1)
Throw exception or return error.
Definition JThrow.hh:51
static void Throw(const bool option)
Enable/disable throw option.
Definition JThrow.hh:37
static bool do_throw
throw option
Definition JThrow.hh:28
Auxiliary classes and methods for language specific functionality.
This name space includes all other name spaces (except KM3NETDAQ, KM3NET and ANTARES).