GException.hpp
25.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
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
/***************************************************************************
* GException.hpp - Exception handler *
* ----------------------------------------------------------------------- *
* copyright (C) 2006-2015 by Juergen Knoedlseder *
* ----------------------------------------------------------------------- *
* *
* 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 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
***************************************************************************/
/**
* @file GException.hpp
* @brief Exception handler interface definition.
* @author Juergen Knoedlseder
*/
#ifndef GEXCEPTION_HPP
#define GEXCEPTION_HPP
/* __ Includes ___________________________________________________________ */
#include <string> // string
#include <vector> // string
#include <sstream> // ostringstream
#include <stdexcept> // exception
#include "GTime.hpp"
#include "GXmlElement.hpp"
/***********************************************************************//**
* @class GExceptionHandler
*
* @brief Interface for exception handler.
***************************************************************************/
class GExceptionHandler : public std::exception {
public:
GExceptionHandler() { }
virtual ~GExceptionHandler() throw() { }
virtual const char* what() const throw();
protected:
std::string m_origin;
std::string m_message;
};
/***********************************************************************//**
* @class GException
*
* @brief Interface for exceptions
*
* The exception class is the master class that is thrown in case of
* exceptions.
***************************************************************************/
class GException : public GExceptionHandler {
public:
// --- LOGIC EXCEPTIONS (what client could have tested) ---
// Invalid value
class invalid_value : public GExceptionHandler {
public:
invalid_value(const std::string& origin,
const std::string& message);
};
// Invalid argument
class invalid_argument : public GExceptionHandler {
public:
invalid_argument(const std::string& origin,
const std::string& message);
invalid_argument(const std::string& origin,
const std::string& argument,
const std::string& message);
};
// Out of range
class out_of_range : public GExceptionHandler {
public:
out_of_range(std::string origin, int inx, int min, int max);
out_of_range(std::string origin, double value, double min, double max);
out_of_range(std::string origin, int inx, int elements);
out_of_range(std::string origin, int row, int col, int rows, int cols);
// New methods
out_of_range(const std::string& origin,
const std::string& what,
const int& index,
const int& elements,
const std::string& message = "");
};
// FITS error
class fits_error : public GExceptionHandler {
public:
fits_error(const std::string& origin,
const int& status,
const std::string& message = "");
};
// --- RUNTIME EXCEPTIONS (not testable by client) ---
// Runtime error
class runtime_error : public GExceptionHandler {
public:
runtime_error(const std::string& origin,
const std::string& message = "");
};
//underflow_error
//overflow_error
// File error
class file_error : public GExceptionHandler {
public:
file_error(const std::string& origin,
const std::string& message = "");
};
// Feature not implemented
class feature_not_implemented : public GExceptionHandler {
public:
feature_not_implemented(const std::string& origin,
const std::string& message = "");
};
// --- OLD EXCEPTIONS ---
// Invalid type conversion
class bad_type : public GExceptionHandler {
public:
bad_type(std::string origin,
std::string message = "");
};
// Environment variable not found
class env_not_found : public GExceptionHandler {
public:
env_not_found(std::string origin,
std::string envname,
std::string message = "");
};
// Memory allocation exception class
class mem_alloc : public GExceptionHandler {
public:
mem_alloc(std::string origin, unsigned num);
};
// Not enough nodes
class not_enough_nodes : public GExceptionHandler {
public:
not_enough_nodes(std::string origin, int num);
};
// File not found
class file_not_found : public GExceptionHandler {
public:
file_not_found(std::string origin,
std::string filename,
std::string message = "");
};
// File open error
class file_open_error : public GExceptionHandler {
public:
file_open_error(std::string origin,
std::string filename,
std::string message = "");
};
// Directory not found
class directory_not_found : public GExceptionHandler {
public:
directory_not_found(std::string origin,
std::string dirname,
std::string message = "");
};
// Directory not accessible
class directory_not_accessible : public GExceptionHandler {
public:
directory_not_accessible(std::string origin,
std::string dirname,
std::string message = "");
};
// Empty object exception class
class empty : public GExceptionHandler {
public:
empty(std::string origin);
};
// Vector - Vector mismatch
class vector_mismatch : public GExceptionHandler {
public:
vector_mismatch(std::string origin, int size1, int size2);
};
// Cross product only defined for 3-element vectors
class vector_bad_cross_dim : public GExceptionHandler {
public:
vector_bad_cross_dim(std::string origin, int elements);
};
// Vector - Matrix mismatch
class matrix_vector_mismatch : public GExceptionHandler {
public:
matrix_vector_mismatch(std::string origin, int num, int rows, int cols);
};
// Matrix dimensions mismatch
class matrix_mismatch : public GExceptionHandler {
public:
matrix_mismatch(std::string origin, int rows1, int cols1, int rows2,
int cols2);
};
// Matrix not square
class matrix_not_square : public GExceptionHandler {
public:
matrix_not_square(std::string origin, int rows, int cols);
};
// Matrix not positive definite
class matrix_not_pos_definite : public GExceptionHandler {
public:
matrix_not_pos_definite(std::string origin, int row, double sum);
};
// Matrix not symmetric
class matrix_not_symmetric : public GExceptionHandler {
public:
matrix_not_symmetric(std::string origin, int cols, int rows);
};
// Matrix not factorised
class matrix_not_factorised : public GExceptionHandler {
public:
matrix_not_factorised(std::string origin, std::string type);
};
// All matrix elements are zero
class matrix_zero : public GExceptionHandler {
public:
matrix_zero(std::string origin);
};
// Invalid ordering scheme
class invalid_order : public GExceptionHandler {
public:
invalid_order(std::string origin, int order, int min_order,
int max_order);
};
// FITS exceptions
class fits_open_error : public GExceptionHandler {
public:
fits_open_error(std::string origin,
std::string filename,
int status,
std::string message = "");
};
class fits_file_exist : public GExceptionHandler {
public:
fits_file_exist(std::string origin,
std::string filename,
int status = 0);
};
class fits_file_not_open : public GExceptionHandler {
public:
fits_file_not_open(std::string origin,
std::string filename);
};
class fits_already_opened : public GExceptionHandler {
public:
fits_already_opened(std::string origin,
std::string filename);
};
/*
class fits_key_not_found : public GExceptionHandler {
public:
fits_key_not_found(std::string origin,
std::string keyname,
int status = 0);
};
*/
class fits_column_not_found : public GExceptionHandler {
public:
fits_column_not_found(std::string origin,
std::string colname,
int status = 0);
};
class fits_no_header : public GExceptionHandler {
public:
fits_no_header(std::string origin,
std::string message,
int status = 0);
};
class fits_no_data : public GExceptionHandler {
public:
fits_no_data(std::string origin,
std::string message,
int status = 0);
};
class fits_hdu_not_found : public GExceptionHandler {
public:
fits_hdu_not_found(std::string origin,
std::string extname,
int status = 0);
fits_hdu_not_found(std::string origin,
int extno,
int status = 0);
};
class fits_hdu_not_image : public GExceptionHandler {
public:
fits_hdu_not_image(std::string origin,
std::string extname,
int type);
};
class fits_hdu_not_table : public GExceptionHandler {
public:
fits_hdu_not_table(std::string origin,
std::string extname,
int type);
};
class fits_unknown_HDU_type : public GExceptionHandler {
public:
fits_unknown_HDU_type(std::string origin,
int type);
};
class fits_invalid_type : public GExceptionHandler {
public:
fits_invalid_type(std::string origin,
std::string message);
};
class fits_unknown_tabtype : public GExceptionHandler {
public:
fits_unknown_tabtype(std::string origin,
int type);
};
class fits_unknown_coltype : public GExceptionHandler {
public:
fits_unknown_coltype(std::string origin,
std::string colname,
int type);
};
class fits_bad_col_length : public GExceptionHandler {
public:
fits_bad_col_length(std::string origin,
int length,
int rows);
};
class fits_bad_bitpix : public GExceptionHandler {
public:
fits_bad_bitpix(std::string origin,
int bitpix);
};
class fits_wrong_image_operator : public GExceptionHandler {
public:
fits_wrong_image_operator(std::string origin,
int naxis,
int nargs);
};
class fits_invalid_row : public GExceptionHandler {
public:
fits_invalid_row(std::string origin,
int row,
int nrows,
std::string message = "");
};
class fits_invalid_nrows : public GExceptionHandler {
public:
fits_invalid_nrows(std::string origin,
int nrows,
int max_rows,
std::string message = "");
};
class fits_inconsistent_tdim : public GExceptionHandler {
public:
fits_inconsistent_tdim(std::string origin,
std::vector<int> tdim,
int number,
std::string message = "");
};
// GSkymap exceptions
class skymap : public GExceptionHandler {
public:
skymap(std::string origin, std::string message = "");
};
class skymap_bad_par : public GExceptionHandler {
public:
skymap_bad_par(std::string origin, int par, std::string message = "");
};
class skymap_bad_size : public GExceptionHandler {
public:
skymap_bad_size(std::string origin, int size, int expected,
std::string message = "");
};
class skymap_bad_ctype : public GExceptionHandler {
public:
skymap_bad_ctype(std::string origin, std::string ctype1,
std::string ctype2, std::string message = "");
};
class skymap_bad_image_dim : public GExceptionHandler {
public:
skymap_bad_image_dim(std::string origin, int naxis,
std::string message = "");
};
// GWcs exceptions
class wcs : public GExceptionHandler {
public:
wcs(std::string origin, std::string message = "");
};
class wcs_invalid : public GExceptionHandler {
public:
wcs_invalid(std::string origin, std::string wcs,
std::string message = "");
};
class wcs_bad_coords : public GExceptionHandler {
public:
wcs_bad_coords(std::string origin, std::string coordsys);
};
class wcs_no_proj_fct : public GExceptionHandler {
public:
wcs_no_proj_fct(std::string origin, std::string message = "");
};
class wcs_hpx_bad_nside : public GExceptionHandler {
public:
wcs_hpx_bad_nside(std::string origin, int nside);
};
class wcs_hpx_bad_ordering : public GExceptionHandler {
public:
wcs_hpx_bad_ordering(std::string origin, std::string ordering);
};
class wcs_singular_matrix : public GExceptionHandler {
public:
wcs_singular_matrix(std::string origin, int naxis,
const std::vector<double>& mat);
};
class wcs_invalid_parameter : public GExceptionHandler {
public:
wcs_invalid_parameter(std::string origin, std::string message = "");
};
class wcs_invalid_x_y : public GExceptionHandler {
public:
wcs_invalid_x_y(std::string origin, int num, std::string message = "");
};
class wcs_invalid_phi_theta : public GExceptionHandler {
public:
wcs_invalid_phi_theta(std::string origin, int num, std::string message = "");
};
// Application exceptions
class app_error : public GExceptionHandler {
public:
app_error(const std::string& origin,
const std::string& message = "");
};
class par_file_not_found : public GExceptionHandler {
public:
par_file_not_found(const std::string& origin,
const std::string& filename,
const std::string& message = "");
};
class par_file_open_error : public GExceptionHandler {
public:
par_file_open_error(const std::string& origin,
const std::string& filename,
const std::string& message = "");
};
class home_not_found : public GExceptionHandler {
public:
home_not_found(const std::string& origin,
const std::string& message = "");
};
class could_not_create_pfiles : public GExceptionHandler {
public:
could_not_create_pfiles(const std::string& origin,
const std::string& home,
const std::string& message = "");
};
class pfiles_not_accessible : public GExceptionHandler {
public:
pfiles_not_accessible(const std::string& origin,
const std::string& home,
const std::string& message = "");
};
class par_file_syntax_error : public GExceptionHandler {
public:
par_file_syntax_error(const std::string& origin,
const std::string& home,
const std::string& message = "");
};
class par_error : public GExceptionHandler {
public:
par_error(const std::string& origin,
const std::string& name,
const std::string& message = "");
};
class bad_cmdline_argument : public GExceptionHandler {
public:
bad_cmdline_argument(const std::string& origin,
const std::string& arg,
const std::string& message = "");
};
// Observation exceptions
class no_response : public GExceptionHandler {
public:
no_response(std::string origin, std::string message = "");
};
class no_roi : public GExceptionHandler {
public:
no_roi(std::string origin, std::string message = "");
};
class no_events : public GExceptionHandler {
public:
no_events(std::string origin, std::string message = "");
};
class no_list : public GExceptionHandler {
public:
no_list(std::string origin, std::string message = "");
};
class no_cube : public GExceptionHandler {
public:
no_cube(std::string origin, std::string message = "");
};
class gradient_par_mismatch : public GExceptionHandler {
public:
gradient_par_mismatch(std::string origin, int nsize, int npars);
};
class caldb_not_found : public GExceptionHandler {
public:
caldb_not_found(std::string origin, std::string home,
std::string message = "");
};
class rsp_invalid_type : public GExceptionHandler {
public:
rsp_invalid_type(std::string origin, std::string type,
std::string message = "");
};
class gti_invalid : public GExceptionHandler {
public:
gti_invalid(std::string origin, GTime tstart, GTime tstop,
std::string message = "");
};
class erange_invalid : public GExceptionHandler {
public:
erange_invalid(std::string origin, double emin,
double emax, std::string message = "");
};
class invalid_statistics : public GExceptionHandler {
public:
invalid_statistics(std::string origin, std::string statistics,
std::string message = "");
};
class invalid_instrument : public GExceptionHandler {
public:
invalid_instrument(std::string origin, std::string instrument,
std::string message = "");
};
class time_invalid_unit : public GExceptionHandler {
public:
time_invalid_unit(const std::string& origin,
const std::string& unit,
const std::string& message = "");
};
class no_valid_time_ref : public GExceptionHandler {
public:
no_valid_time_ref(const std::string& origin,
const std::string& message = "");
};
// XML exceptions
class xml_syntax_error : public GExceptionHandler {
public:
xml_syntax_error(std::string origin, std::string segment,
std::string message = "");
};
class xml_attribute_value : public GExceptionHandler {
public:
xml_attribute_value(std::string origin, std::string value);
};
class xml_bad_node_type : public GExceptionHandler {
public:
xml_bad_node_type(std::string origin, std::string type,
std::string message = "");
};
class xml_name_not_found : public GExceptionHandler {
public:
xml_name_not_found(std::string origin, std::string type,
std::string message = "");
};
class xml_invalid_parnum : public GExceptionHandler {
public:
xml_invalid_parnum(std::string origin, GXmlElement xml,
std::string message = "");
};
class xml_invalid_parnames : public GExceptionHandler {
public:
xml_invalid_parnames(std::string origin, GXmlElement xml,
std::string message = "");
};
// Model exceptions
class model_invalid : public GExceptionHandler {
public:
model_invalid(std::string origin, std::string type,
std::string message = "");
};
class model_invalid_spatial : public GExceptionHandler {
public:
model_invalid_spatial(std::string origin, std::string type,
std::string message = "");
};
class model_invalid_spectral : public GExceptionHandler {
public:
model_invalid_spectral(std::string origin, std::string type,
std::string message = "");
};
class model_invalid_temporal : public GExceptionHandler {
public:
model_invalid_temporal(std::string origin, std::string type,
std::string message = "");
};
class model_invalid_parnum : public GExceptionHandler {
public:
model_invalid_parnum(std::string origin, GXmlElement xml,
std::string message = "");
};
class model_invalid_parnames : public GExceptionHandler {
public:
model_invalid_parnames(std::string origin, GXmlElement xml,
std::string message = "");
};
class model_invalid_parvalue : public GExceptionHandler {
public:
model_invalid_parvalue(std::string origin, GXmlElement xml,
std::string message = "");
};
class model_invalid_parlimit : public GExceptionHandler {
public:
model_invalid_parlimit(std::string origin, GXmlElement xml,
std::string message = "");
};
class model_invalid_parscale : public GExceptionHandler {
public:
model_invalid_parscale(std::string origin, double scale,
std::string message = "");
model_invalid_parscale(std::string origin, GXmlElement xml,
std::string message = "");
};
class file_function_data : public GExceptionHandler {
public:
file_function_data(std::string origin, std::string filename,
int num, std::string message = "");
};
class file_function_columns : public GExceptionHandler {
public:
file_function_columns(std::string origin, std::string filename,
int num, std::string message = "");
};
class file_function_value : public GExceptionHandler {
public:
file_function_value(std::string origin, std::string filename,
double value, std::string message = "");
};
class par_not_found : public GExceptionHandler {
public:
par_not_found(std::string origin, std::string name,
std::string message = "");
};
class model_not_found : public GExceptionHandler {
public:
model_not_found(std::string origin, std::string name,
std::string message = "");
};
class no_point_source : public GExceptionHandler {
public:
no_point_source(std::string origin, std::string name,
std::string message = "");
};
class no_extended_source : public GExceptionHandler {
public:
no_extended_source(std::string origin, std::string name,
std::string message = "");
};
// CSV exceptions
class csv_bad_columns : public GExceptionHandler {
public:
csv_bad_columns(std::string origin, std::string filename,
int rows, int cols, int elements,
std::string message = "");
};
// Test exceptions
class test_nested_try_error : public GExceptionHandler {
public:
test_nested_try_error(std::string origin, std::string message = "");
};
class test_failure : public GExceptionHandler {
public:
test_failure(std::string origin, std::string message = "");
};
class test_error : public GExceptionHandler {
public:
test_error(std::string origin, std::string message = "");
};
};
#endif /* GEXCEPTION_HPP */