GammaLib  2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GException.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GException.hpp - Exception handler *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2006-2021 by Juergen Knoedlseder *
5  * ----------------------------------------------------------------------- *
6  * *
7  * This program is free software: you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation, either version 3 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This program is distributed in the hope that it will be useful, *
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15  * GNU General Public License for more details. *
16  * *
17  * You should have received a copy of the GNU General Public License *
18  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
19  * *
20  ***************************************************************************/
21 /**
22  * @file GException.hpp
23  * @brief Exception handler interface definition.
24  * @author Juergen Knoedlseder
25  */
26 
27 #ifndef GEXCEPTION_HPP
28 #define GEXCEPTION_HPP
29 
30 /* __ Includes ___________________________________________________________ */
31 #include <string> // string
32 #include <stdexcept> // exception
33 
34 /* __ Forward declarations ______________________________________________ */
35 class GEnergy;
36 
37 /* __ Prototypes ________________________________________________________ */
38 namespace gammalib {
39  void check_energy_interval(const std::string& origin,
40  const GEnergy& emin,
41  const GEnergy& emax);
42  void check_prj_x2s_status(const std::string& origin,
43  const int& status,
44  const int& number);
45  void check_prj_s2x_status(const std::string& origin,
46  const int& status,
47  const int& number);
48 }
49 
50 
51 /***********************************************************************//**
52  * @class GExceptionHandler
53  *
54  * @brief Interface for exception handler.
55  ***************************************************************************/
56 class GExceptionHandler : public std::exception {
57 public:
59  virtual ~GExceptionHandler() throw() { }
60  virtual const char* what() const throw();
61 protected:
62  std::string m_origin;
63  std::string m_message;
64 };
65 
66 
67 /***********************************************************************//**
68  * @class GException
69  *
70  * @brief Interface for exceptions
71  *
72  * The exception class is the master class that is thrown in case of
73  * exceptions.
74  ***************************************************************************/
75 class GException : public GExceptionHandler {
76 public:
77 
78  // --- LOGIC EXCEPTIONS (what client could have tested) ---
79 
80  // Invalid value
81  class invalid_value : public GExceptionHandler {
82  public:
83  invalid_value(const std::string& origin,
84  const std::string& message);
85  };
86 
87  // Invalid argument
88  class invalid_argument : public GExceptionHandler {
89  public:
90  invalid_argument(const std::string& origin,
91  const std::string& message);
92  invalid_argument(const std::string& origin,
93  const std::string& argument,
94  const std::string& message);
95  };
96 
97  // Invalid return value
98  class invalid_return_value : public GExceptionHandler {
99  public:
100  invalid_return_value(const std::string& origin,
101  const std::string& message);
102  };
103 
104  // Out of range
105  class out_of_range : public GExceptionHandler {
106  public:
107  out_of_range(const std::string& origin,
108  const std::string& what,
109  const int& index,
110  const int& elements,
111  const std::string& message = "");
112  };
113 
114  // FITS error
115  class fits_error : public GExceptionHandler {
116  public:
117  fits_error(const std::string& origin,
118  const int& status,
119  const std::string& message = "");
120  };
121 
122 
123  // --- RUNTIME EXCEPTIONS (not testable by client) ---
124 
125  // Runtime error
126  class runtime_error : public GExceptionHandler {
127  public:
128  runtime_error(const std::string& origin,
129  const std::string& message = "");
130  };
131 
132  //underflow_error
133 
134  //overflow_error
135 
136  // File error
137  class file_error : public GExceptionHandler {
138  public:
139  file_error(const std::string& origin,
140  const std::string& message = "");
141  };
142 
143  // Feature not implemented
144  class feature_not_implemented : public GExceptionHandler {
145  public:
146  feature_not_implemented(const std::string& origin,
147  const std::string& message = "");
148  };
149 
150 
151  // --- TEST EXCEPTIONS (only used by test suite) ---
152 
153  // Signal nested try
154  class test_nested_try_error : public GExceptionHandler {
155  public:
156  test_nested_try_error(const std::string& origin,
157  const std::string& message = "");
158  };
159 
160  // Signal test failure
161  class test_failure : public GExceptionHandler {
162  public:
163  test_failure(const std::string& origin,
164  const std::string& message = "");
165  };
166 
167  // Signal test error
168  class test_error : public GExceptionHandler {
169  public:
170  test_error(const std::string& origin,
171  const std::string& message = "");
172  };
173 
174 };
175 
176 #endif /* GEXCEPTION_HPP */
std::string number(const std::string &noun, const int &number)
Convert singular noun into number noun.
Definition: GTools.cpp:1167
virtual ~GExceptionHandler()
Definition: GException.hpp:59
Interface for exception handler.
Definition: GException.hpp:56
void check_energy_interval(const std::string &origin, const GEnergy &emin, const GEnergy &emax)
Checks energy interval.
Definition: GException.cpp:364
std::string m_message
Definition: GException.hpp:63
virtual const char * what() const
Exception message.
Definition: GException.cpp:37
void check_prj_s2x_status(const std::string &origin, const int &status, const int &number)
Checks status of GWcs::prj_s2x method.
Definition: GException.cpp:438
void check_prj_x2s_status(const std::string &origin, const int &status, const int &number)
Checks status of GWcs::prj_x2s method.
Definition: GException.cpp:401
std::string m_origin
Definition: GException.hpp:62
Class that handles energies in a unit independent way.
Definition: GEnergy.hpp:48
Interface for exceptions.
Definition: GException.hpp:75