GException.cpp
17.1 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
/***************************************************************************
* GException.cpp - exception handler *
* ----------------------------------------------------------------------- *
* copyright : (C) 2006 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. *
* *
***************************************************************************/
/* __ Includes ___________________________________________________________ */
#include "GException.hpp"
#include "GFitsCfitsio.hpp"
/* __ Namespaces _________________________________________________________ */
using namespace std;
/***************************************************************************
* Private conversion functions *
***************************************************************************/
std::string str(int value)
{
ostringstream s_value;
s_value << value;
return s_value.str();
}
std::string str(double value)
{
ostringstream s_value;
s_value << scientific << value;
return s_value.str();
}
/***************************************************************************
* Exception handler base class definition *
***************************************************************************/
const char* GExceptionHandler::what() const throw()
{
string message = "*** ERROR in " + m_origin + ": " + m_message;
return message.c_str();
}
/***************************************************************************
* Memory allocation exception *
***************************************************************************/
GException::mem_alloc::mem_alloc(string origin, unsigned num)
{
m_origin = origin;
m_message = "Memory allocation error (" + str((int)num) + " elements)";
}
/***************************************************************************
* Empty object exception *
***************************************************************************/
GException::empty::empty(string origin)
{
m_origin = origin;
m_message = "Zero-size allocation";
}
/***************************************************************************
* Index out of range *
***************************************************************************/
GException::out_of_range::out_of_range(string origin, int inx, int min, int max)
{
m_origin = origin;
m_message = "Index (" + str(inx) + ") out of range [" + str(min) +
"," + str(max) + "]";
}
/***************************************************************************
* Vector index out of range *
***************************************************************************/
GException::out_of_range::out_of_range(string origin, int inx, int elements)
{
m_origin = origin;
if (elements > 0) {
m_message = "Vector index (" + str(inx) + ") out of range [0," +
str(elements-1) + "]";
}
else {
m_message = "Empty vector";
}
}
/***************************************************************************
* Matrix row or column out of range *
***************************************************************************/
GException::out_of_range::out_of_range(string origin, int row, int col, int rows, int cols)
{
m_origin = origin;
m_message = "Matrix element (" + str(row) + "," + str(col) +
") out of range ([0," + str(rows) + "], [0," +
str(cols) + "])";
}
/***************************************************************************
* Vector dimensions differ *
***************************************************************************/
GException::vector_mismatch::vector_mismatch(string origin, int size1, int size2)
{
m_origin = origin;
m_message = "Vector dimensions differ (" + str(size1) + " <-> " +
str(size2) + ")";
}
/***************************************************************************
* Invalid vector dimension for cross product *
***************************************************************************/
GException::vector_bad_cross_dim::vector_bad_cross_dim(string origin, int elements)
{
m_origin = origin;
m_message = "Vector cross product only defined for 3 dimensions but vector size is " +
str(elements);
}
/***************************************************************************
* Mismatch between matrix and vector *
***************************************************************************/
GException::matrix_vector_mismatch::matrix_vector_mismatch(string origin, int num, int rows, int cols)
{
m_origin = origin;
m_message = "Vector dimension [" + str(num) +
"] is incompatible with matrix size [" +
str(rows) + "," + str(cols) + "]";
}
/***************************************************************************
* Matrix mismatch in operation *
***************************************************************************/
GException::matrix_mismatch::matrix_mismatch(string origin, int rows1, int cols1, int rows2, int cols2)
{
m_origin = origin;
m_message = "Matrix mismatch: M1(" + str(rows1) + "," + str(cols1) +
") incompatible with M2(" + str(rows2) + "," + str(cols2) + ")";
}
/***************************************************************************
* Matrix not rectangular *
***************************************************************************/
GException::matrix_not_rectangular::matrix_not_rectangular(string origin, int rows, int cols)
{
m_origin = origin;
m_message = "Matrix is not rectangular [" + str(rows) + "," + str(cols) + "]";
}
/***************************************************************************
* Matrix is not positive definite *
***************************************************************************/
GException::matrix_not_pos_definite::matrix_not_pos_definite(string origin, int row, double sum)
{
m_origin = origin;
m_message = "Matrix is not positive definite (sum " + str(sum) +
" occured in row/column " + str(row) + ")";
}
/***************************************************************************
* Matrix is not symmetric *
***************************************************************************/
GException::matrix_not_symmetric::matrix_not_symmetric(string origin, int cols, int rows)
{
m_origin = origin;
m_message = "Matrix is not symmetric [" + str(rows) + "," + str(cols) + "]";
}
/***************************************************************************
* Matrix has not been factorised *
***************************************************************************/
GException::matrix_not_factorised::matrix_not_factorised(string origin, string type)
{
m_origin = origin;
m_message = "Matrix has not been factorised using " + type;
}
/***************************************************************************
* All matrix elements are zero *
***************************************************************************/
GException::matrix_zero::matrix_zero(string origin)
{
m_origin = origin;
m_message = "All matrix elements are zero";
}
/***************************************************************************
* Invalid ordering scheme requested *
***************************************************************************/
GException::invalid_order::invalid_order(string origin, int order, int min_order, int max_order)
{
m_origin = origin;
m_message = "Invalid ordering type " + str(order) +
"requested; must be comprised in [" + str(min_order) +
"," + str(max_order) + "]";
}
/***********************************************************************//**
* @brief General FITS error
*
* @param[in] origin Method that throws the error.
* @param[in] status cfitsio status.
***************************************************************************/
GException::fits_error::fits_error(string origin, int status)
{
m_origin = origin;
ostringstream s_error;
char err_text[31];
__ffgerr(status, err_text);
s_error << err_text << " (status=" << status << ")";
m_message = s_error.str();
}
/***********************************************************************//**
* @brief FITS error: unable to open FITS file
*
* @param[in] origin Method that throws the error.
* @param[in] filename Name of the file for which opening was attempted.
* @param[in] status cfitsio status.
***************************************************************************/
GException::fits_open_error::fits_open_error(string origin,
string filename,
int status)
{
m_origin = origin;
m_message = "Unable to open FITS file '" + filename + "'";
if (status != 0)
m_message += " (status=" + str(status) + ")";
}
/***********************************************************************//**
* @brief FITS error: attempted to overwrite FITS file
*
* @param[in] origin Method that throws the error.
* @param[in] filename Name of the file for which overwrite attempt was made.
* @param[in] status cfitsio status.
***************************************************************************/
GException::fits_file_exist::fits_file_exist(string origin,
string filename,
int status)
{
m_origin = origin;
m_message = "Attempted to overwrite FITS file '" + filename + "'";
if (status != 0)
m_message += " (status=" + str(status) + ")";
}
/***********************************************************************//**
* @brief FITS error: file already open
*
* @param[in] origin Method that throws the error.
* @param[in] filename Name of file that is already open.
***************************************************************************/
GException::fits_already_opened::fits_already_opened(string origin,
string filename)
{
m_origin = origin;
m_message = "FITS file '" + filename + "' is already open";
}
/***********************************************************************//**
* @brief FITS error: Keyword not in header
*
* @param[in] origin Method that throws the error.
* @param[in] keyname Name of keyword that was not found.
* @param[in] status cfitsio status.
***************************************************************************/
GException::fits_key_not_found::fits_key_not_found(string origin,
string keyname,
int status)
{
m_origin = origin;
m_message = "Keyword '" + keyname + "' not found in header";
if (status != 0)
m_message += " (status=" + str(status) + ")";
}
/***********************************************************************//**
* @brief FITS error: Table column not found
*
* @param[in] origin Method that throws the error.
* @param[in] colname Name of the table column that was not found.
* @param[in] status cfitsio status.
***************************************************************************/
GException::fits_column_not_found::fits_column_not_found(string origin,
string colname,
int status)
{
m_origin = origin;
m_message = "Column '" + colname + "' not found in table";
if (status != 0)
m_message += " (status=" + str(status) + ")";
}
/***********************************************************************//**
* @brief FITS error: HDU not found in FITS file
*
* @param[in] origin Method that throws the error.
* @param[in] extname Name of the extension that was not found.
* @param[in] status cfitsio status.
***************************************************************************/
GException::fits_hdu_not_found::fits_hdu_not_found(string origin,
string extname,
int status)
{
m_origin = origin;
m_message = "HDU '" + extname + "' not found in FITS file";
if (status != 0)
m_message += " (status=" + str(status) + ")";
}
/***********************************************************************//**
* @brief FITS error: HDU of unknown type found
*
* @param[in] origin Method that throws the error.
* @param[in] type Specified HDU type.
***************************************************************************/
GException::fits_unknown_HDU_type::fits_unknown_HDU_type(string origin,
int type)
{
m_origin = origin;
m_message = "HDU type '" + str(type) + "' is not known";
}
/***********************************************************************//**
* @brief FITS error: HDU is not a table
*
* @param[in] origin Method that throws the error.
* @param[in] type Specified HDU type.
***************************************************************************/
GException::fits_HDU_not_a_table::fits_HDU_not_a_table(string origin,
int type)
{
m_origin = origin;
m_message = "HDU is not of type 'table' (type=" + str(type) + ")";
}
/***********************************************************************//**
* @brief FITS error: Invalid type
*
* @param[in] origin Method that throws the error.
* @param[in] message Error message.
***************************************************************************/
GException::fits_invalid_type::fits_invalid_type(string origin,
string message)
{
m_origin = origin;
m_message = message;
}
/***********************************************************************//**
* @brief FITS error: Column type is unknown
*
* @param[in] origin Method that throws the error.
* @param[in] type Specified column type.
***************************************************************************/
GException::fits_unknown_coltype::fits_unknown_coltype(string origin,
int type)
{
m_origin = origin;
m_message = "Column type '" + str(type) + "' is unknown";
}
/***********************************************************************//**
* @brief FITS error: invalid number of bits per pixel
*
* @param[in] origin Method that throws the error.
* @param[in] bitpix Bitpix value that was not 8,16,32,64,-32, or -64.
***************************************************************************/
GException::fits_bad_bitpix::fits_bad_bitpix(string origin,
int bitpix)
{
m_origin = origin;
m_message = "Invalid number of bits per pixel (bitpix="+str(bitpix)+")";
}
/***********************************************************************//**
* @brief FITS error: wrong image operator has been used
*
* @param[in] origin Method that throws the error.
* @param[in] naxis Dimension of image.
* @param[in] nargs Number of arguments of the image operator.
***************************************************************************/
GException::fits_wrong_image_operator::fits_wrong_image_operator(string origin,
int naxis,
int nargs)
{
m_origin = origin;
m_message = "Wrong image pixel access operator has been used (dimension=" +
str(naxis) + " <=> arguments=" + str(nargs) + ")";
}
/***********************************************************************//**
* @brief Response error: invalid response type specified
*
* @param[in] origin Method that throws the error.
* @param[in] type Specified response type.
***************************************************************************/
GException::rsp_invalid_type::rsp_invalid_type(string origin,
string type)
{
m_origin = origin;
m_message = "Invalid response type '"+type+"' specified";
}