GammaLib 2.2.0.dev
Loading...
Searching...
No Matches
GException.hpp
Go to the documentation of this file.
1/***************************************************************************
2 * GException.hpp - Exception handler *
3 * ----------------------------------------------------------------------- *
4 * copyright (C) 2006-2026 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 ______________________________________________ */
35class GEnergy;
36
37/* __ Prototypes ________________________________________________________ */
38namespace 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 ***************************************************************************/
56class GExceptionHandler : public std::exception {
57public:
59 virtual ~GExceptionHandler() throw();
60 virtual const char* what() const throw();
61protected:
62 std::string m_origin; //!< Method that threw exception
63 std::string m_message; //!< Exception message
64 mutable char* m_str; //!< Message returned by what()
65};
66
67
68/***********************************************************************//**
69 * @class GException
70 *
71 * @brief Interface for exceptions
72 *
73 * The exception class is the master class that is thrown in case of
74 * exceptions.
75 ***************************************************************************/
77public:
78
79 // --- LOGIC EXCEPTIONS (what client could have tested) ---
80
81 // Invalid value
83 public:
84 invalid_value(const std::string& origin,
85 const std::string& message);
86 };
87
88 // Invalid argument
90 public:
91 invalid_argument(const std::string& origin,
92 const std::string& message);
93 invalid_argument(const std::string& origin,
94 const std::string& argument,
95 const std::string& message);
96 };
97
98 // Invalid return value
100 public:
101 invalid_return_value(const std::string& origin,
102 const std::string& message);
103 };
104
105 // Out of range
107 public:
108 out_of_range(const std::string& origin,
109 const std::string& what,
110 const int& index,
111 const int& elements,
112 const std::string& message = "");
113 };
114
115 // FITS error
117 public:
118 fits_error(const std::string& origin,
119 const int& status,
120 const std::string& message = "");
121 };
122
123
124 // --- RUNTIME EXCEPTIONS (not testable by client) ---
125
126 // Runtime error
128 public:
129 runtime_error(const std::string& origin,
130 const std::string& message = "");
131 };
132
133 //underflow_error
134
135 //overflow_error
136
137 // File error
139 public:
140 file_error(const std::string& origin,
141 const std::string& message = "");
142 };
143
144 // Feature not implemented
146 public:
147 feature_not_implemented(const std::string& origin,
148 const std::string& message = "");
149 };
150
151
152 // --- TEST EXCEPTIONS (only used by test suite) ---
153
154 // Signal nested try
156 public:
157 test_nested_try_error(const std::string& origin,
158 const std::string& message = "");
159 };
160
161 // Signal test failure
163 public:
164 test_failure(const std::string& origin,
165 const std::string& message = "");
166 };
167
168 // Signal test error
170 public:
171 test_error(const std::string& origin,
172 const std::string& message = "");
173 };
174
175};
176
177#endif /* GEXCEPTION_HPP */
Class that handles energies in a unit independent way.
Definition GEnergy.hpp:48
Interface for exception handler.
GExceptionHandler()
Void constructor.
virtual const char * what() const
Exception message.
virtual ~GExceptionHandler()
Destructor.
std::string m_message
Exception message.
char * m_str
Message returned by what()
std::string m_origin
Method that threw exception.
feature_not_implemented(const std::string &origin, const std::string &message="")
Feature not implement.
file_error(const std::string &origin, const std::string &message="")
File error.
fits_error(const std::string &origin, const int &status, const std::string &message="")
General FITS error.
invalid_argument(const std::string &origin, const std::string &message)
Invalid argument.
invalid_return_value(const std::string &origin, const std::string &message)
Invalid return value.
invalid_value(const std::string &origin, const std::string &message)
Invalid value.
out_of_range(const std::string &origin, const std::string &what, const int &index, const int &elements, const std::string &message="")
Index is out of range [0,elements-1].
runtime_error(const std::string &origin, const std::string &message="")
Runtime error.
test_error(const std::string &origin, const std::string &message="")
Failure test.
test_failure(const std::string &origin, const std::string &message="")
Failure test.
test_nested_try_error(const std::string &origin, const std::string &message="")
Test nested try error.
Interface for exceptions.
void check_energy_interval(const std::string &origin, const GEnergy &emin, const GEnergy &emax)
Checks energy interval.
std::string number(const std::string &noun, const int &number)
Convert singular noun into number noun.
Definition GTools.cpp:1160
void check_prj_s2x_status(const std::string &origin, const int &status, const int &number)
Checks status of GWcs::prj_s2x method.
void check_prj_x2s_status(const std::string &origin, const int &status, const int &number)
Checks status of GWcs::prj_x2s method.