GammaLib  1.7.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GMWLException.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GMWLException.cpp - Multi-wavelength exception handler *
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 GMWLException.cpp
23  * @brief MWL exception handler interface implementation.
24  * @author J. Knoedlseder
25  */
26 
27 /* __ Includes ___________________________________________________________ */
28 #include "GMWLException.hpp"
29 #include "GTools.hpp"
30 
31 
32 /***********************************************************************//**
33  * @brief Exception message
34  ***************************************************************************/
35 const char* GMWLExceptionHandler::what() const throw()
36 {
37  // Set error message
38  std::string message = "*** ERROR in " + m_origin + ": " + m_message;
39 
40  // Return message as C character array
41  return gammalib::tochar(message);
42 }
43 
44 
45 /***********************************************************************//**
46  * @brief Error while opening file
47  *
48  * @param[in] origin Name of method that has thrown the exception.
49  * @param[in] filename Name of file that could not be opened.
50  * @param[in] message Optional error message.
51  ***************************************************************************/
53  std::string filename,
54  std::string message)
55 {
56  // Set origin
57  m_origin = origin;
58 
59  // Set message
60  m_message = "Unable to open file \""+filename+"\".";
61 
62  // Append optional message
63  if (message.length() > 0) {
64  m_message += " "+message;
65  }
66 
67  // Return
68  return;
69 }
70 
71 
72 /***********************************************************************//**
73  * @brief File has invalid format
74  *
75  * @param[in] origin Name of method that has thrown the exception.
76  * @param[in] message Optional error message.
77  ***************************************************************************/
79  std::string message)
80 {
81  // Set origin
82  m_origin = origin;
83 
84  // Set message
85  m_message = "File has invalid format.";
86 
87  // Append optional message
88  if (message.length() > 0) {
89  m_message += " "+message;
90  }
91 
92  // Return
93  return;
94 }
95 
96 
97 /***********************************************************************//**
98  * @brief Invalid or unsupported unit encountered
99  *
100  * @param[in] origin Name of method that has thrown the exception.
101  * @param[in] unit Unit string.
102  * @param[in] message Optional error message.
103  ***************************************************************************/
105  std::string unit,
106  std::string message)
107 {
108  // Set origin
109  m_origin = origin;
110 
111  // Set message
112  m_message = "Invalid or unsupported unit \""+unit+"\" encountered.";
113 
114  // Append optional message
115  if (message.length() > 0) {
116  m_message += " "+message;
117  }
118 
119  // Return
120  return;
121 }
122 
123 
124 /***********************************************************************//**
125  * @brief Response is not a MWL response
126  *
127  * @param[in] origin Name of method that has thrown the exception.
128  * @param[in] message Optional error message.
129  ***************************************************************************/
131  std::string message)
132 {
133  // Set origin
134  m_origin = origin;
135 
136  // Set message
137  m_message = "Response is not of type GMWLResponse.";
138 
139  // Append optional message
140  if (message.length() > 0) {
141  m_message += " "+message;
142  }
143 
144  // Return
145  return;
146 }
Gammalib tools definition.
virtual const char * what() const
Exception message.
char * tochar(const std::string &arg)
Convert string to C string.
Definition: GTools.cpp:646
invalid_unit(std::string origin, std::string unit, std::string message="")
Invalid or unsupported unit encountered.
MWL exception handler interface definition.
bad_response_type(std::string origin, std::string message="")
Response is not a MWL response.
file_open_error(std::string origin, std::string filename, std::string message="")
Error while opening file.
bad_file_format(std::string origin, std::string message="")
File has invalid format.