GException.cpp
5.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/***************************************************************************
* GException.cpp - exception handlers *
* ----------------------------------------------------------------------- *
* copyright (C) 2006-2010 by Jurgen Knodlseder *
* ----------------------------------------------------------------------- *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
/**
* @file GException.cpp
* @brief Exception handler interface implementation.
* @author J. Knodlseder
*/
/* __ Includes ___________________________________________________________ */
#include "GException.hpp"
#include "GTools.hpp"
/***********************************************************************//**
* @brief Exception message.
***************************************************************************/
const char* GExceptionHandler::what() const throw()
{
std::string message = "*** ERROR in " + m_origin + ": " + m_message;
return message.c_str();
}
/***********************************************************************//**
* @brief Feature not implement
*
* @param[in] origin Name of method that has thrown the exception.
* @param[in] message Optional message.
***************************************************************************/
GException::feature_not_implemented::feature_not_implemented(std::string origin,
std::string message)
{
m_origin = origin;
if (message.length() > 0)
m_message = message;
else
m_message = "Feature not implemented.";
m_message += " In case that you need this feature for your application"
" please submit a feature request on"
" https://sourceforge.net/projects/gammalib/,"
" join this error message and provide a detailed"
" description of your needs.";
return;
}
/***********************************************************************//**
* @brief Bad type
*
* @param[in] origin Name of method that has thrown the exception.
* @param[in] message Optional message.
***************************************************************************/
GException::bad_type::bad_type(std::string origin, std::string message)
{
m_origin = origin;
m_message = "Invalud type conversion. " + message;
return;
}
/***********************************************************************//**
* @brief Memory allocation exception.
*
* @param[in] origin Name of method that has thrown the exception.
* @param[in] num Requested amount of memory.
***************************************************************************/
GException::mem_alloc::mem_alloc(std::string origin, unsigned num)
{
m_origin = origin;
m_message = "Memory allocation error (" + str((int)num) + " elements)";
return;
}
/***********************************************************************//**
* @brief Not enough nodes in node array
*
* @param[in] origin Name of method that has thrown the exception.
* @param[in] num Number of nodes in node array.
***************************************************************************/
GException::not_enough_nodes::not_enough_nodes(std::string origin, int num)
{
m_origin = origin;
m_message = "Not enough nodes in node array (" + str(num) + " nodes).";
return;
}
/***********************************************************************//**
* @brief File not found
*
* @param[in] origin Name of method that has thrown the exception.
* @param[in] filename Filename.
***************************************************************************/
GException::file_not_found::file_not_found(std::string origin, std::string filename)
{
m_origin = origin;
m_message = "File \"" + filename +"\" not found.";
return;
}
/***********************************************************************//**
* @brief File open error
*
* @param[in] origin Name of method that has thrown the exception.
* @param[in] filename Filename.
***************************************************************************/
GException::file_open_error::file_open_error(std::string origin, std::string filename)
{
m_origin = origin;
m_message = "Unable to open file \"" + filename +"\"";
return;
}
/***********************************************************************//**
* @brief Bad CSV columns encountered
*
* @param[in] origin Name of method that has thrown the exception.
* @param[in] filename Filename.
* @param[in] row CSV file row.
* @param[in] cols Expected number of columns.
* @param[in] elements Found number of columns.
* @param[in] message Optional message.
***************************************************************************/
GException::cvs_bad_columns::cvs_bad_columns(std::string origin,
std::string filename,
int row,
int cols,
int elements,
std::string message)
{
m_origin = origin;
m_message = "Inconsistent number of columns found in row "+str(row)+
" of file \""+filename+"\" ("+str(cols)+" expected, "+
str(elements)+" encountered). "+message;
return;
}