GammaLib  1.7.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GException_app.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GException_app.cpp - Application exception handlers *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2010-2012 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_app.cpp
23  * @brief Application exception handler interface definition
24  * @author Juergen Knoedlseder
25  */
26 
27 /* __ Includes ___________________________________________________________ */
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31 #include "GException.hpp"
32 #include "GTools.hpp"
33 
34 
35 /***********************************************************************//**
36  * @brief Generic application error
37  *
38  * @param[in] origin Method that throws the error.
39  * @param[in] message Optional error message.
40  ***************************************************************************/
41 GException::app_error::app_error(const std::string& origin,
42  const std::string& message)
43 {
44  // Set origin
45  m_origin = origin;
46 
47  // Set message
48  m_message = message;
49 
50  // Return
51  return;
52 }
53 
54 
55 /***********************************************************************//**
56  * @brief Parameter file not found
57  *
58  * @param[in] origin Method that throws the error.
59  * @param[in] filename Filename that was not found.
60  * @param[in] message Optional error message.
61  ***************************************************************************/
63  const std::string& filename,
64  const std::string& message)
65 {
66  // Set origin and message
67  m_origin = origin;
68  m_message = "Parameter file \""+filename+"\" not found. "
69  "Make sure that PFILES environment variable is set "
70  "correctly.";
71 
72  // Add optional error message
73  if (message.length() > 0) {
74  m_message += " " + message;
75  }
76 
77  // Return
78  return;
79 }
80 
81 
82 /***********************************************************************//**
83  * @brief Unable to open parameter file
84  *
85  * @param[in] origin Method that throws the error.
86  * @param[in] filename Filename that could not be opened.
87  * @param[in] message Optional error message.
88  ***************************************************************************/
90  const std::string& filename,
91  const std::string& message)
92 {
93  // Set origin and message
94  m_origin = origin;
95  m_message = "Unable to open parameter file \""+filename+"\".";
96 
97  // Add optional error message
98  if (message.length() > 0) {
99  m_message += " " + message;
100  }
101 
102  // Return
103  return;
104 }
105 
106 
107 /***********************************************************************//**
108  * @brief Unable to determine users home directory
109  *
110  * @param[in] origin Method that throws the error.
111  * @param[in] message Optional error message.
112  ***************************************************************************/
114  const std::string& message)
115 {
116  // Set origin and message
117  m_origin = origin;
118  m_message = "Unable to determine users home directory.";
119 
120  // Add optional error message
121  if (message.length() > 0) {
122  m_message += " " + message;
123  }
124 
125  // Return
126  return;
127 }
128 
129 
130 /***********************************************************************//**
131  * @brief Unable to create pfiles directory in users home directory
132  *
133  * @param[in] origin Method that throws the error.
134  * @param[in] home Users home directory.
135  * @param[in] message Optional error message.
136  ***************************************************************************/
138  const std::string& home,
139  const std::string& message)
140 {
141  // Set origin and message
142  m_origin = origin;
143  m_message = "Unable to create \""+home+"\".";
144 
145  // Add optional error message
146  if (message.length() > 0) {
147  m_message += " " + message;
148  }
149 
150  // Return
151  return;
152 }
153 
154 
155 /***********************************************************************//**
156  * @brief Unable to change access rights for pfiles directory
157  *
158  * @param[in] origin Method that throws the error.
159  * @param[in] home Users home directory.
160  * @param[in] message Optional error message.
161  ***************************************************************************/
163  const std::string& home,
164  const std::string& message)
165 {
166  // Set origin and message
167  m_origin = origin;
168  m_message = "Could not make \""+home+"\" write accessible for "
169  "writing of the applications parameter file.";
170 
171  // Add optional error message
172  if (message.length() > 0) {
173  m_message += " " + message;
174  }
175 
176  // Return
177  return;
178 }
179 
180 
181 /***********************************************************************//**
182  * @brief Syntax error encountered in parameter file line
183  *
184  * @param[in] origin Method that throws the error.
185  * @param[in] line Parameter file line in which syntax error occured.
186  * @param[in] message Optional error message.
187  ***************************************************************************/
189  const std::string& line,
190  const std::string& message)
191 {
192  // Set origin and message
193  m_origin = origin;
194  if (message.length() > 0) {
195  m_message = "Syntax error occured in the following line of the "
196  "parameter file ("+message+"): "+line;
197  }
198  else {
199  m_message = "Syntax error occured in the following line of the "
200  "parameter file: "+line;
201  }
202 
203  // Return
204  return;
205 }
206 
207 
208 /***********************************************************************//**
209  * @brief Error encountered in parameter definition
210  *
211  * @param[in] origin Method that throws the error.
212  * @param[in] name Parameter name.
213  * @param[in] message Optional error message.
214  ***************************************************************************/
215 GException::par_error::par_error(const std::string& origin,
216  const std::string& name,
217  const std::string& message)
218 {
219  // Set origin
220  m_origin = origin;
221 
222  // Set message
223  m_message = "Parameter \""+name+"\"";
224 
225  // Add optional error message
226  if (message.length() > 0) {
227  m_message += ": " + message;
228  }
229 
230  // Return
231  return;
232 }
233 
234 
235 /***********************************************************************//**
236  * @brief Invalid command line parameter
237  *
238  * @param[in] origin Method that throws the error.
239  * @param[in] arg Command line argument.
240  * @param[in] message Optional error message.
241  ***************************************************************************/
243  const std::string& arg,
244  const std::string& message)
245 {
246  // Set origin and message
247  m_origin = origin;
248  if (message.length() > 0) {
249  m_message = "Invalid command line parameter encountered ("+message+
250  "): "+arg;
251  }
252  else {
253  m_message = "Invalid command line parameter encountered: "+arg;
254  }
255 
256  // Return
257  return;
258 }
259 
pfiles_not_accessible(const std::string &origin, const std::string &home, const std::string &message="")
Unable to change access rights for pfiles directory.
could_not_create_pfiles(const std::string &origin, const std::string &home, const std::string &message="")
Unable to create pfiles directory in users home directory.
Gammalib tools definition.
par_file_syntax_error(const std::string &origin, const std::string &home, const std::string &message="")
Syntax error encountered in parameter file line.
par_error(const std::string &origin, const std::string &name, const std::string &message="")
Error encountered in parameter definition.
home_not_found(const std::string &origin, const std::string &message="")
Unable to determine users home directory.
std::string m_message
Definition: GException.hpp:51
bad_cmdline_argument(const std::string &origin, const std::string &arg, const std::string &message="")
Invalid command line parameter.
app_error(const std::string &origin, const std::string &message="")
Generic application error.
Exception handler interface definition.
std::string m_origin
Definition: GException.hpp:50
par_file_open_error(const std::string &origin, const std::string &filename, const std::string &message="")
Unable to open parameter file.
par_file_not_found(const std::string &origin, const std::string &filename, const std::string &message="")
Parameter file not found.