GammaLib  1.7.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GException.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GException.hpp - Exception handler *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2006-2017 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.hpp
23  * @brief Exception handler interface definition.
24  * @author Juergen Knoedlseder
25  */
26 
27 #ifndef GEXCEPTION_HPP
28 #define GEXCEPTION_HPP
29 
30 /* __ Includes ___________________________________________________________ */
31 #include <string> // string
32 #include <vector> // string
33 #include <sstream> // ostringstream
34 #include <stdexcept> // exception
35 #include "GTime.hpp"
36 #include "GXmlElement.hpp"
37 
38 
39 /***********************************************************************//**
40  * @class GExceptionHandler
41  *
42  * @brief Interface for exception handler.
43  ***************************************************************************/
44 class GExceptionHandler : public std::exception {
45 public:
47  virtual ~GExceptionHandler() throw() { }
48  virtual const char* what() const throw();
49 protected:
50  std::string m_origin;
51  std::string m_message;
52 };
53 
54 
55 /***********************************************************************//**
56  * @class GException
57  *
58  * @brief Interface for exceptions
59  *
60  * The exception class is the master class that is thrown in case of
61  * exceptions.
62  ***************************************************************************/
63 class GException : public GExceptionHandler {
64 public:
65 
66  // --- LOGIC EXCEPTIONS (what client could have tested) ---
67 
68  // Invalid value
69  class invalid_value : public GExceptionHandler {
70  public:
71  invalid_value(const std::string& origin,
72  const std::string& message);
73  };
74 
75  // Invalid argument
76  class invalid_argument : public GExceptionHandler {
77  public:
78  invalid_argument(const std::string& origin,
79  const std::string& message);
80  invalid_argument(const std::string& origin,
81  const std::string& argument,
82  const std::string& message);
83  };
84 
85  // Invalid return value
86  class invalid_return_value : public GExceptionHandler {
87  public:
88  invalid_return_value(const std::string& origin,
89  const std::string& message);
90  };
91 
92  // Out of range
93  class out_of_range : public GExceptionHandler {
94  public:
95  out_of_range(std::string origin, int inx, int min, int max);
96  out_of_range(std::string origin, double value, double min, double max);
97  out_of_range(std::string origin, int inx, int elements);
98  out_of_range(std::string origin, int row, int col, int rows, int cols);
99  // New methods
100  out_of_range(const std::string& origin,
101  const std::string& what,
102  const int& index,
103  const int& elements,
104  const std::string& message = "");
105  };
106 
107  // FITS error
108  class fits_error : public GExceptionHandler {
109  public:
110  fits_error(const std::string& origin,
111  const int& status,
112  const std::string& message = "");
113  };
114 
115 
116  // --- RUNTIME EXCEPTIONS (not testable by client) ---
117 
118  // Runtime error
119  class runtime_error : public GExceptionHandler {
120  public:
121  runtime_error(const std::string& origin,
122  const std::string& message = "");
123  };
124 
125  //underflow_error
126 
127  //overflow_error
128 
129  // File error
130  class file_error : public GExceptionHandler {
131  public:
132  file_error(const std::string& origin,
133  const std::string& message = "");
134  };
135 
136  // Feature not implemented
137  class feature_not_implemented : public GExceptionHandler {
138  public:
139  feature_not_implemented(const std::string& origin,
140  const std::string& message = "");
141  };
142 
143  // --- OLD EXCEPTIONS ---
144 
145 
146 
147 
148  // Invalid type conversion
149  class bad_type : public GExceptionHandler {
150  public:
151  bad_type(std::string origin,
152  std::string message = "");
153  };
154 
155  // Environment variable not found
156  class env_not_found : public GExceptionHandler {
157  public:
158  env_not_found(std::string origin,
159  std::string envname,
160  std::string message = "");
161  };
162 
163  // Memory allocation exception class
164  class mem_alloc : public GExceptionHandler {
165  public:
166  mem_alloc(std::string origin, unsigned num);
167  };
168 
169  // Not enough nodes
170  class not_enough_nodes : public GExceptionHandler {
171  public:
172  not_enough_nodes(std::string origin, int num);
173  };
174 
175  // File not found
176  class file_not_found : public GExceptionHandler {
177  public:
178  file_not_found(std::string origin,
179  std::string filename,
180  std::string message = "");
181  };
182 
183  // File open error
184  class file_open_error : public GExceptionHandler {
185  public:
186  file_open_error(std::string origin,
187  std::string filename,
188  std::string message = "");
189  };
190 
191  // Directory not found
192  class directory_not_found : public GExceptionHandler {
193  public:
194  directory_not_found(std::string origin,
195  std::string dirname,
196  std::string message = "");
197  };
198 
199  // Directory not accessible
200  class directory_not_accessible : public GExceptionHandler {
201  public:
202  directory_not_accessible(std::string origin,
203  std::string dirname,
204  std::string message = "");
205  };
206 
207  // Empty object exception class
208  class empty : public GExceptionHandler {
209  public:
210  empty(std::string origin);
211  };
212 
213  // Vector - Vector mismatch
214  class vector_mismatch : public GExceptionHandler {
215  public:
216  vector_mismatch(std::string origin, int size1, int size2);
217  };
218 
219  // Cross product only defined for 3-element vectors
220  class vector_bad_cross_dim : public GExceptionHandler {
221  public:
222  vector_bad_cross_dim(std::string origin, int elements);
223  };
224 
225  // Vector - Matrix mismatch
226  class matrix_vector_mismatch : public GExceptionHandler {
227  public:
228  matrix_vector_mismatch(std::string origin, int num, int rows, int cols);
229  };
230 
231  // Matrix dimensions mismatch
232  class matrix_mismatch : public GExceptionHandler {
233  public:
234  matrix_mismatch(std::string origin, int rows1, int cols1, int rows2,
235  int cols2);
236  };
237 
238  // Matrix not square
239  class matrix_not_square : public GExceptionHandler {
240  public:
241  matrix_not_square(std::string origin, int rows, int cols);
242  };
243 
244  // Matrix not positive definite
245  class matrix_not_pos_definite : public GExceptionHandler {
246  public:
247  matrix_not_pos_definite(std::string origin, int row, double sum);
248  };
249 
250  // Matrix not symmetric
251  class matrix_not_symmetric : public GExceptionHandler {
252  public:
253  matrix_not_symmetric(std::string origin, int cols, int rows);
254  };
255 
256  // Matrix not factorised
257  class matrix_not_factorised : public GExceptionHandler {
258  public:
259  matrix_not_factorised(std::string origin, std::string type);
260  };
261 
262  // All matrix elements are zero
263  class matrix_zero : public GExceptionHandler {
264  public:
265  matrix_zero(std::string origin);
266  };
267 
268  // Invalid ordering scheme
269  class invalid_order : public GExceptionHandler {
270  public:
271  invalid_order(std::string origin, int order, int min_order,
272  int max_order);
273  };
274 
275 
276  // FITS exceptions
277  class fits_open_error : public GExceptionHandler {
278  public:
279  fits_open_error(std::string origin,
280  std::string filename,
281  int status,
282  std::string message = "");
283  };
284  class fits_file_exist : public GExceptionHandler {
285  public:
286  fits_file_exist(std::string origin,
287  std::string filename,
288  int status = 0);
289  };
290  class fits_file_not_open : public GExceptionHandler {
291  public:
292  fits_file_not_open(std::string origin,
293  std::string filename);
294  };
295  class fits_already_opened : public GExceptionHandler {
296  public:
297  fits_already_opened(std::string origin,
298  std::string filename);
299  };
300  /*
301  class fits_key_not_found : public GExceptionHandler {
302  public:
303  fits_key_not_found(std::string origin,
304  std::string keyname,
305  int status = 0);
306  };
307  */
308  class fits_column_not_found : public GExceptionHandler {
309  public:
310  fits_column_not_found(std::string origin,
311  std::string colname,
312  int status = 0);
313  };
314  class fits_no_header : public GExceptionHandler {
315  public:
316  fits_no_header(std::string origin,
317  std::string message,
318  int status = 0);
319  };
320  class fits_no_data : public GExceptionHandler {
321  public:
322  fits_no_data(std::string origin,
323  std::string message,
324  int status = 0);
325  };
326  class fits_hdu_not_found : public GExceptionHandler {
327  public:
328  fits_hdu_not_found(std::string origin,
329  std::string extname,
330  int status = 0);
331  fits_hdu_not_found(std::string origin,
332  int extno,
333  int status = 0);
334  };
335  class fits_hdu_not_image : public GExceptionHandler {
336  public:
337  fits_hdu_not_image(std::string origin,
338  std::string extname,
339  int type);
340  };
341  class fits_hdu_not_table : public GExceptionHandler {
342  public:
343  fits_hdu_not_table(std::string origin,
344  std::string extname,
345  int type);
346  };
347  class fits_unknown_HDU_type : public GExceptionHandler {
348  public:
349  fits_unknown_HDU_type(std::string origin,
350  int type);
351  };
352  class fits_invalid_type : public GExceptionHandler {
353  public:
354  fits_invalid_type(std::string origin,
355  std::string message);
356  };
357  class fits_unknown_tabtype : public GExceptionHandler {
358  public:
359  fits_unknown_tabtype(std::string origin,
360  int type);
361  };
362  class fits_unknown_coltype : public GExceptionHandler {
363  public:
364  fits_unknown_coltype(std::string origin,
365  std::string colname,
366  int type);
367  };
368  class fits_bad_col_length : public GExceptionHandler {
369  public:
370  fits_bad_col_length(std::string origin,
371  int length,
372  int rows);
373  };
374  class fits_bad_bitpix : public GExceptionHandler {
375  public:
376  fits_bad_bitpix(std::string origin,
377  int bitpix);
378  };
379  class fits_wrong_image_operator : public GExceptionHandler {
380  public:
381  fits_wrong_image_operator(std::string origin,
382  int naxis,
383  int nargs);
384  };
385  class fits_invalid_row : public GExceptionHandler {
386  public:
387  fits_invalid_row(std::string origin,
388  int row,
389  int nrows,
390  std::string message = "");
391  };
392  class fits_invalid_nrows : public GExceptionHandler {
393  public:
394  fits_invalid_nrows(std::string origin,
395  int nrows,
396  int max_rows,
397  std::string message = "");
398  };
399  class fits_inconsistent_tdim : public GExceptionHandler {
400  public:
401  fits_inconsistent_tdim(std::string origin,
402  std::vector<int> tdim,
403  int number,
404  std::string message = "");
405  };
406 
407 
408  // GSkyMap exceptions
409  class skymap : public GExceptionHandler {
410  public:
411  skymap(std::string origin, std::string message = "");
412  };
413  class skymap_bad_par : public GExceptionHandler {
414  public:
415  skymap_bad_par(std::string origin, int par, std::string message = "");
416  };
417  class skymap_bad_size : public GExceptionHandler {
418  public:
419  skymap_bad_size(std::string origin, int size, int expected,
420  std::string message = "");
421  };
422  class skymap_bad_ctype : public GExceptionHandler {
423  public:
424  skymap_bad_ctype(std::string origin, std::string ctype1,
425  std::string ctype2, std::string message = "");
426  };
427  class skymap_bad_image_dim : public GExceptionHandler {
428  public:
429  skymap_bad_image_dim(std::string origin, int naxis,
430  std::string message = "");
431  };
432 
433 
434  // GWcs exceptions
435  class wcs : public GExceptionHandler {
436  public:
437  wcs(std::string origin, std::string message = "");
438  };
439  class wcs_invalid : public GExceptionHandler {
440  public:
441  wcs_invalid(std::string origin, std::string wcs,
442  std::string message = "");
443  };
444  class wcs_bad_coords : public GExceptionHandler {
445  public:
446  wcs_bad_coords(std::string origin, std::string coordsys);
447  };
448  class wcs_no_proj_fct : public GExceptionHandler {
449  public:
450  wcs_no_proj_fct(std::string origin, std::string message = "");
451  };
452  class wcs_hpx_bad_nside : public GExceptionHandler {
453  public:
454  wcs_hpx_bad_nside(std::string origin, int nside);
455  };
456  class wcs_hpx_bad_ordering : public GExceptionHandler {
457  public:
458  wcs_hpx_bad_ordering(std::string origin, std::string ordering);
459  };
460  class wcs_singular_matrix : public GExceptionHandler {
461  public:
462  wcs_singular_matrix(std::string origin, int naxis,
463  const std::vector<double>& mat);
464  };
465  class wcs_invalid_parameter : public GExceptionHandler {
466  public:
467  wcs_invalid_parameter(std::string origin, std::string message = "");
468  };
469  class wcs_invalid_x_y : public GExceptionHandler {
470  public:
471  wcs_invalid_x_y(std::string origin, int num, std::string message = "");
472  };
473  class wcs_invalid_phi_theta : public GExceptionHandler {
474  public:
475  wcs_invalid_phi_theta(std::string origin, int num, std::string message = "");
476  };
477 
478 
479  // Application exceptions
480  class app_error : public GExceptionHandler {
481  public:
482  app_error(const std::string& origin,
483  const std::string& message = "");
484  };
485  class par_file_not_found : public GExceptionHandler {
486  public:
487  par_file_not_found(const std::string& origin,
488  const std::string& filename,
489  const std::string& message = "");
490  };
491  class par_file_open_error : public GExceptionHandler {
492  public:
493  par_file_open_error(const std::string& origin,
494  const std::string& filename,
495  const std::string& message = "");
496  };
497  class home_not_found : public GExceptionHandler {
498  public:
499  home_not_found(const std::string& origin,
500  const std::string& message = "");
501  };
502  class could_not_create_pfiles : public GExceptionHandler {
503  public:
504  could_not_create_pfiles(const std::string& origin,
505  const std::string& home,
506  const std::string& message = "");
507  };
508  class pfiles_not_accessible : public GExceptionHandler {
509  public:
510  pfiles_not_accessible(const std::string& origin,
511  const std::string& home,
512  const std::string& message = "");
513  };
514  class par_file_syntax_error : public GExceptionHandler {
515  public:
516  par_file_syntax_error(const std::string& origin,
517  const std::string& home,
518  const std::string& message = "");
519  };
520  class par_error : public GExceptionHandler {
521  public:
522  par_error(const std::string& origin,
523  const std::string& name,
524  const std::string& message = "");
525  };
526  class bad_cmdline_argument : public GExceptionHandler {
527  public:
528  bad_cmdline_argument(const std::string& origin,
529  const std::string& arg,
530  const std::string& message = "");
531  };
532 
533 
534  // Observation exceptions
535  class no_response : public GExceptionHandler {
536  public:
537  no_response(std::string origin, std::string message = "");
538  };
539  class no_roi : public GExceptionHandler {
540  public:
541  no_roi(std::string origin, std::string message = "");
542  };
543  class no_events : public GExceptionHandler {
544  public:
545  no_events(std::string origin, std::string message = "");
546  };
547  class no_list : public GExceptionHandler {
548  public:
549  no_list(std::string origin, std::string message = "");
550  };
551  class no_cube : public GExceptionHandler {
552  public:
553  no_cube(std::string origin, std::string message = "");
554  };
555  class gradient_par_mismatch : public GExceptionHandler {
556  public:
557  gradient_par_mismatch(std::string origin, int nsize, int npars);
558  };
559  class caldb_not_found : public GExceptionHandler {
560  public:
561  caldb_not_found(std::string origin, std::string home,
562  std::string message = "");
563  };
564  class rsp_invalid_type : public GExceptionHandler {
565  public:
566  rsp_invalid_type(std::string origin, std::string type,
567  std::string message = "");
568  };
569  class gti_invalid : public GExceptionHandler {
570  public:
571  gti_invalid(std::string origin, GTime tstart, GTime tstop,
572  std::string message = "");
573  };
574  class erange_invalid : public GExceptionHandler {
575  public:
576  erange_invalid(std::string origin, double emin,
577  double emax, std::string message = "");
578  };
579  class invalid_statistics : public GExceptionHandler {
580  public:
581  invalid_statistics(std::string origin, std::string statistics,
582  std::string message = "");
583  };
584  class invalid_instrument : public GExceptionHandler {
585  public:
586  invalid_instrument(std::string origin, std::string instrument,
587  std::string message = "");
588  };
589  class time_invalid_unit : public GExceptionHandler {
590  public:
591  time_invalid_unit(const std::string& origin,
592  const std::string& unit,
593  const std::string& message = "");
594  };
595  class no_valid_time_ref : public GExceptionHandler {
596  public:
597  no_valid_time_ref(const std::string& origin,
598  const std::string& message = "");
599  };
600 
601 
602  // XML exceptions
603  class xml_syntax_error : public GExceptionHandler {
604  public:
605  xml_syntax_error(std::string origin, std::string segment,
606  std::string message = "");
607  };
608  class xml_attribute_value : public GExceptionHandler {
609  public:
610  xml_attribute_value(std::string origin, std::string value);
611  };
612  class xml_bad_node_type : public GExceptionHandler {
613  public:
614  xml_bad_node_type(std::string origin, std::string type,
615  std::string message = "");
616  };
617  class xml_name_not_found : public GExceptionHandler {
618  public:
619  xml_name_not_found(std::string origin, std::string type,
620  std::string message = "");
621  };
622  class xml_invalid_parnum : public GExceptionHandler {
623  public:
624  xml_invalid_parnum(std::string origin, GXmlElement xml,
625  std::string message = "");
626  };
627  class xml_invalid_parnames : public GExceptionHandler {
628  public:
629  xml_invalid_parnames(std::string origin, GXmlElement xml,
630  std::string message = "");
631  };
632 
633 
634  // Model exceptions
635  class model_invalid : public GExceptionHandler {
636  public:
637  model_invalid(std::string origin, std::string type,
638  std::string message = "");
639  };
640  class model_invalid_spatial : public GExceptionHandler {
641  public:
642  model_invalid_spatial(std::string origin, std::string type,
643  std::string message = "");
644  };
645  class model_invalid_spectral : public GExceptionHandler {
646  public:
647  model_invalid_spectral(std::string origin, std::string type,
648  std::string message = "");
649  };
650  class model_invalid_temporal : public GExceptionHandler {
651  public:
652  model_invalid_temporal(std::string origin, std::string type,
653  std::string message = "");
654  };
655  class model_invalid_parnum : public GExceptionHandler {
656  public:
657  model_invalid_parnum(std::string origin, GXmlElement xml,
658  std::string message = "");
659  };
660  class model_invalid_nodenum : public GExceptionHandler {
661  public:
662  model_invalid_nodenum(std::string origin, GXmlElement xml,
663  std::string message = "");
664  };
665  class model_invalid_parnames : public GExceptionHandler {
666  public:
667  model_invalid_parnames(std::string origin, GXmlElement xml,
668  std::string message = "");
669  };
670  class model_invalid_parvalue : public GExceptionHandler {
671  public:
672  model_invalid_parvalue(std::string origin, GXmlElement xml,
673  std::string message = "");
674  };
675  class model_invalid_parlimit : public GExceptionHandler {
676  public:
677  model_invalid_parlimit(std::string origin, GXmlElement xml,
678  std::string message = "");
679  };
680  class model_invalid_parscale : public GExceptionHandler {
681  public:
682  model_invalid_parscale(std::string origin, double scale,
683  std::string message = "");
684  model_invalid_parscale(std::string origin, GXmlElement xml,
685  std::string message = "");
686  };
687  class file_function_data : public GExceptionHandler {
688  public:
689  file_function_data(std::string origin, std::string filename,
690  int num, std::string message = "");
691  };
692  class file_function_columns : public GExceptionHandler {
693  public:
694  file_function_columns(std::string origin, std::string filename,
695  int num, std::string message = "");
696  };
697  class file_function_value : public GExceptionHandler {
698  public:
699  file_function_value(std::string origin, std::string filename,
700  double value, std::string message = "");
701  };
702  class par_not_found : public GExceptionHandler {
703  public:
704  par_not_found(std::string origin, std::string name,
705  std::string message = "");
706  };
707  class model_not_found : public GExceptionHandler {
708  public:
709  model_not_found(std::string origin, std::string name,
710  std::string message = "");
711  };
712  class no_point_source : public GExceptionHandler {
713  public:
714  no_point_source(std::string origin, std::string name,
715  std::string message = "");
716  };
717  class no_extended_source : public GExceptionHandler {
718  public:
719  no_extended_source(std::string origin, std::string name,
720  std::string message = "");
721  };
722 
723  // CSV exceptions
724  class csv_bad_columns : public GExceptionHandler {
725  public:
726  csv_bad_columns(std::string origin, std::string filename,
727  int rows, int cols, int elements,
728  std::string message = "");
729  };
730 
731  // Test exceptions
732  class test_nested_try_error : public GExceptionHandler {
733  public:
734  test_nested_try_error(std::string origin, std::string message = "");
735  };
736 
737  class test_failure : public GExceptionHandler {
738  public:
739  test_failure(std::string origin, std::string message = "");
740  };
741 
742  class test_error : public GExceptionHandler {
743  public:
744  test_error(std::string origin, std::string message = "");
745  };
746 
747 };
748 
749 #endif /* GEXCEPTION_HPP */
std::string number(const std::string &noun, const int &number)
Convert singular noun into number noun.
Definition: GTools.cpp:1046
XML element node class interface definition.
virtual ~GExceptionHandler()
Definition: GException.hpp:47
XML element node class.
Definition: GXmlElement.hpp:47
double sum(const GVector &vector)
Computes vector sum.
Definition: GVector.cpp:901
Time class.
Definition: GTime.hpp:54
double min(const GVector &vector)
Computes minimum vector element.
Definition: GVector.cpp:843
Interface for exception handler.
Definition: GException.hpp:44
std::string m_message
Definition: GException.hpp:51
virtual const char * what() const
Exception message.
Definition: GException.cpp:35
double max(const GVector &vector)
Computes maximum vector element.
Definition: GVector.cpp:872
std::string m_origin
Definition: GException.hpp:50
Time class interface definition.
Interface for exceptions.
Definition: GException.hpp:63