include/GException.hpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *                    GException.hpp - Exception handler                   *
00003  * ----------------------------------------------------------------------- *
00004  *  copyright (C) 2006-2015 by Juergen Knoedlseder                         *
00005  * ----------------------------------------------------------------------- *
00006  *                                                                         *
00007  *  This program is free software: you can redistribute it and/or modify   *
00008  *  it under the terms of the GNU General Public License as published by   *
00009  *  the Free Software Foundation, either version 3 of the License, or      *
00010  *  (at your option) any later version.                                    *
00011  *                                                                         *
00012  *  This program is distributed in the hope that it will be useful,        *
00013  *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
00014  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
00015  *  GNU General Public License for more details.                           *
00016  *                                                                         *
00017  *  You should have received a copy of the GNU General Public License      *
00018  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.  *
00019  *                                                                         *
00020  ***************************************************************************/
00021 /**
00022  * @file GException.hpp
00023  * @brief Exception handler interface definition.
00024  * @author Juergen Knoedlseder
00025  */
00026 
00027 #ifndef GEXCEPTION_HPP
00028 #define GEXCEPTION_HPP
00029 
00030 /* __ Includes ___________________________________________________________ */
00031 #include <string>                             // string
00032 #include <vector>                             // string
00033 #include <sstream>                            // ostringstream
00034 #include <stdexcept>                          // exception
00035 #include "GTime.hpp"
00036 #include "GXmlElement.hpp"
00037 
00038 
00039 /***********************************************************************//**
00040  * @class GExceptionHandler
00041  *
00042  * @brief Interface for exception handler.
00043  ***************************************************************************/
00044 class GExceptionHandler : public std::exception {
00045 public:
00046     GExceptionHandler() { }
00047     virtual ~GExceptionHandler() throw() { }
00048     virtual const char* what() const throw();
00049 protected:
00050     std::string m_origin;
00051     std::string m_message;
00052 };
00053 
00054 
00055 /***********************************************************************//**
00056  * @class GException
00057  *
00058  * @brief Interface for exceptions
00059  *
00060  * The exception class is the master class that is thrown in case of
00061  * exceptions.
00062  ***************************************************************************/
00063 class GException : public GExceptionHandler {
00064 public:
00065 
00066     // --- LOGIC EXCEPTIONS (what client could have tested) ---
00067 
00068     // Invalid value
00069     class invalid_value : public GExceptionHandler {
00070     public:
00071         invalid_value(const std::string& origin,
00072                       const std::string& message);
00073     };
00074 
00075     // Invalid argument
00076     class invalid_argument : public GExceptionHandler {
00077     public:
00078         invalid_argument(const std::string& origin,
00079                          const std::string& message);
00080         invalid_argument(const std::string& origin,
00081                          const std::string& argument,
00082                          const std::string& message);
00083     };
00084 
00085     // Out of range
00086     class out_of_range : public GExceptionHandler {
00087     public:
00088         out_of_range(std::string origin, int inx, int min, int max);
00089         out_of_range(std::string origin, double value, double min, double max);
00090         out_of_range(std::string origin, int inx, int elements);
00091         out_of_range(std::string origin, int row, int col, int rows, int cols);
00092         // New methods
00093         out_of_range(const std::string& origin,
00094                      const std::string& what,
00095                      const int&         index,
00096                      const int&         elements,
00097                      const std::string& message = "");
00098     };
00099 
00100     // FITS error
00101     class fits_error : public GExceptionHandler {
00102     public:
00103         fits_error(const std::string& origin,
00104                    const int&         status,
00105                    const std::string& message = "");
00106     };
00107 
00108 
00109     // --- RUNTIME EXCEPTIONS (not testable by client) ---
00110 
00111     // Runtime error
00112     class runtime_error : public GExceptionHandler {
00113     public:
00114         runtime_error(const std::string& origin,
00115                       const std::string& message = "");
00116     };
00117 
00118     //underflow_error
00119 
00120     //overflow_error
00121 
00122     // File error
00123     class file_error : public GExceptionHandler {
00124     public:
00125         file_error(const std::string& origin,
00126                    const std::string& message = "");
00127     };
00128 
00129     // Feature not implemented
00130     class feature_not_implemented : public GExceptionHandler {
00131     public:
00132         feature_not_implemented(const std::string& origin,
00133                                 const std::string& message = "");
00134     };
00135 
00136     // --- OLD EXCEPTIONS ---
00137 
00138 
00139 
00140 
00141     // Invalid type conversion
00142     class bad_type : public GExceptionHandler {
00143     public:
00144         bad_type(std::string origin,
00145                  std::string message = "");
00146     };
00147 
00148     // Environment variable not found
00149     class env_not_found : public GExceptionHandler {
00150     public:
00151         env_not_found(std::string origin,
00152                       std::string envname,
00153                       std::string message = "");
00154     };
00155 
00156     // Memory allocation exception class
00157     class mem_alloc : public GExceptionHandler {
00158     public:
00159         mem_alloc(std::string origin, unsigned num);
00160     };
00161 
00162     // Not enough nodes
00163     class not_enough_nodes : public GExceptionHandler {
00164     public:
00165         not_enough_nodes(std::string origin, int num);
00166     };
00167 
00168     // File not found
00169     class file_not_found : public GExceptionHandler {
00170     public:
00171         file_not_found(std::string origin,
00172                        std::string filename,
00173                        std::string message = "");
00174     };
00175 
00176     // File open error
00177     class file_open_error : public GExceptionHandler {
00178     public:
00179         file_open_error(std::string origin,
00180                         std::string filename,
00181                         std::string message = "");
00182     };
00183 
00184     // Directory not found
00185     class directory_not_found : public GExceptionHandler {
00186     public:
00187         directory_not_found(std::string origin,
00188                             std::string dirname,
00189                             std::string message = "");
00190     };
00191 
00192     // Directory not accessible
00193     class directory_not_accessible : public GExceptionHandler {
00194     public:
00195         directory_not_accessible(std::string origin,
00196                                  std::string dirname,
00197                                  std::string message = "");
00198     };
00199 
00200     // Empty object exception class
00201     class empty : public GExceptionHandler {
00202     public:
00203         empty(std::string origin);
00204     };
00205 
00206     // Vector - Vector mismatch
00207     class vector_mismatch : public GExceptionHandler {
00208     public:
00209         vector_mismatch(std::string origin, int size1, int size2);
00210     };
00211 
00212     // Cross product only defined for 3-element vectors
00213     class vector_bad_cross_dim : public GExceptionHandler {
00214     public:
00215         vector_bad_cross_dim(std::string origin, int elements);
00216     };
00217 
00218     // Vector - Matrix mismatch
00219     class matrix_vector_mismatch : public GExceptionHandler {
00220     public:
00221         matrix_vector_mismatch(std::string origin, int num, int rows, int cols);
00222     };
00223 
00224     // Matrix dimensions mismatch
00225     class matrix_mismatch : public GExceptionHandler {
00226     public:
00227         matrix_mismatch(std::string origin, int rows1, int cols1, int rows2, 
00228                         int cols2);
00229     };
00230 
00231     // Matrix not square
00232     class matrix_not_square : public GExceptionHandler {
00233     public:
00234         matrix_not_square(std::string origin, int rows, int cols);
00235     };
00236 
00237     // Matrix not positive definite
00238     class matrix_not_pos_definite : public GExceptionHandler {
00239     public:
00240         matrix_not_pos_definite(std::string origin, int row, double sum);
00241     };
00242 
00243     // Matrix not symmetric
00244     class matrix_not_symmetric : public GExceptionHandler {
00245     public:
00246         matrix_not_symmetric(std::string origin, int cols, int rows);
00247     };
00248 
00249     // Matrix not factorised
00250     class matrix_not_factorised : public GExceptionHandler {
00251     public:
00252         matrix_not_factorised(std::string origin, std::string type);
00253     };
00254 
00255     // All matrix elements are zero
00256     class matrix_zero : public GExceptionHandler  {
00257     public:
00258         matrix_zero(std::string origin);
00259     };
00260 
00261     // Invalid ordering scheme
00262     class invalid_order : public GExceptionHandler {
00263     public:
00264         invalid_order(std::string origin, int order, int min_order, 
00265                       int max_order);
00266     };
00267 
00268 
00269     // FITS exceptions
00270     class fits_open_error : public GExceptionHandler {
00271     public:
00272         fits_open_error(std::string origin,
00273                         std::string filename,
00274                         int         status,
00275                         std::string message = "");
00276     };
00277     class fits_file_exist : public GExceptionHandler {
00278     public:
00279         fits_file_exist(std::string origin,
00280                         std::string filename,
00281                         int         status = 0);
00282     };
00283     class fits_file_not_open : public GExceptionHandler {
00284     public:
00285         fits_file_not_open(std::string origin,
00286                            std::string filename);
00287     };
00288     class fits_already_opened : public GExceptionHandler {
00289     public:
00290         fits_already_opened(std::string origin,
00291                             std::string filename);
00292     };
00293     /*
00294     class fits_key_not_found : public GExceptionHandler {
00295     public:
00296         fits_key_not_found(std::string origin,
00297                            std::string keyname, 
00298                            int         status = 0);
00299     };
00300     */
00301     class fits_column_not_found : public GExceptionHandler {
00302     public:
00303         fits_column_not_found(std::string origin,
00304                               std::string colname, 
00305                               int         status = 0);
00306     };
00307     class fits_no_header : public GExceptionHandler {
00308     public:
00309         fits_no_header(std::string origin,
00310                        std::string message,
00311                        int         status = 0);
00312     };
00313     class fits_no_data : public GExceptionHandler {
00314     public:
00315         fits_no_data(std::string origin,
00316                      std::string message,
00317                      int         status = 0);
00318     };
00319     class fits_hdu_not_found : public GExceptionHandler {
00320     public:
00321         fits_hdu_not_found(std::string origin,
00322                            std::string extname,
00323                            int         status = 0);
00324         fits_hdu_not_found(std::string origin,
00325                            int         extno,
00326                            int         status = 0);
00327     };
00328     class fits_hdu_not_image : public GExceptionHandler {
00329     public:
00330         fits_hdu_not_image(std::string origin,
00331                            std::string extname,
00332                            int         type);
00333     };
00334     class fits_hdu_not_table : public GExceptionHandler {
00335     public:
00336         fits_hdu_not_table(std::string origin,
00337                            std::string extname,
00338                            int         type);
00339     };
00340     class fits_unknown_HDU_type : public GExceptionHandler {
00341     public:
00342         fits_unknown_HDU_type(std::string origin,
00343                               int         type);
00344     };
00345     class fits_invalid_type : public GExceptionHandler {
00346     public:
00347         fits_invalid_type(std::string origin,
00348                           std::string message);
00349     };
00350     class fits_unknown_tabtype : public GExceptionHandler {
00351     public:
00352         fits_unknown_tabtype(std::string origin,
00353                              int         type);
00354     };
00355     class fits_unknown_coltype : public GExceptionHandler {
00356     public:
00357         fits_unknown_coltype(std::string origin,
00358                              std::string colname,
00359                              int         type);
00360     };
00361     class fits_bad_col_length : public GExceptionHandler {
00362     public:
00363         fits_bad_col_length(std::string origin,
00364                             int         length,
00365                             int         rows);
00366     };
00367     class fits_bad_bitpix : public GExceptionHandler {
00368     public:
00369         fits_bad_bitpix(std::string origin,
00370                         int         bitpix);
00371     };
00372     class fits_wrong_image_operator : public GExceptionHandler {
00373     public:
00374         fits_wrong_image_operator(std::string origin,
00375                                   int         naxis,
00376                                   int         nargs);
00377     };
00378     class fits_invalid_row : public GExceptionHandler {
00379     public:
00380         fits_invalid_row(std::string origin,
00381                          int         row,
00382                          int         nrows,
00383                          std::string message = "");
00384     };
00385     class fits_invalid_nrows : public GExceptionHandler {
00386     public:
00387         fits_invalid_nrows(std::string origin,
00388                            int         nrows,
00389                            int         max_rows,
00390                            std::string message = "");
00391     };
00392     class fits_inconsistent_tdim : public GExceptionHandler {
00393     public:
00394         fits_inconsistent_tdim(std::string      origin,
00395                                std::vector<int> tdim,
00396                                int              number,
00397                                std::string      message = "");
00398     };
00399 
00400 
00401     // GSkyMap exceptions
00402     class skymap : public GExceptionHandler {
00403     public:
00404         skymap(std::string origin, std::string message = "");
00405     };
00406     class skymap_bad_par : public GExceptionHandler {
00407     public:
00408         skymap_bad_par(std::string origin, int par, std::string message = "");
00409     };
00410     class skymap_bad_size : public GExceptionHandler {
00411     public:
00412         skymap_bad_size(std::string origin, int size, int expected,
00413                         std::string message = "");
00414     };
00415     class skymap_bad_ctype : public GExceptionHandler {
00416     public:
00417         skymap_bad_ctype(std::string origin, std::string ctype1,
00418                          std::string ctype2, std::string message = "");
00419     };
00420     class skymap_bad_image_dim : public GExceptionHandler {
00421     public:
00422         skymap_bad_image_dim(std::string origin, int naxis,
00423                              std::string message = "");
00424     };
00425 
00426 
00427     // GWcs exceptions
00428     class wcs : public GExceptionHandler {
00429     public:
00430         wcs(std::string origin, std::string message = "");
00431     };
00432     class wcs_invalid : public GExceptionHandler {
00433     public:
00434         wcs_invalid(std::string origin, std::string wcs, 
00435                     std::string message = "");
00436     };
00437     class wcs_bad_coords : public GExceptionHandler {
00438     public:
00439         wcs_bad_coords(std::string origin, std::string coordsys);
00440     };
00441     class wcs_no_proj_fct : public GExceptionHandler {
00442     public:
00443         wcs_no_proj_fct(std::string origin, std::string message = "");
00444     };
00445     class wcs_hpx_bad_nside : public GExceptionHandler {
00446     public:
00447         wcs_hpx_bad_nside(std::string origin, int nside);
00448     };
00449     class wcs_hpx_bad_ordering : public GExceptionHandler {
00450     public:
00451         wcs_hpx_bad_ordering(std::string origin, std::string ordering);
00452     };
00453     class wcs_singular_matrix : public GExceptionHandler {
00454     public:
00455         wcs_singular_matrix(std::string origin, int naxis,
00456                             const std::vector<double>& mat);
00457     };
00458     class wcs_invalid_parameter : public GExceptionHandler {
00459     public:
00460         wcs_invalid_parameter(std::string origin, std::string message = "");
00461     };
00462     class wcs_invalid_x_y : public GExceptionHandler {
00463     public:
00464         wcs_invalid_x_y(std::string origin, int num, std::string message = "");
00465     };
00466     class wcs_invalid_phi_theta : public GExceptionHandler {
00467     public:
00468         wcs_invalid_phi_theta(std::string origin, int num, std::string message = "");
00469     };
00470 
00471 
00472     // Application exceptions
00473     class app_error : public GExceptionHandler {
00474     public:
00475         app_error(const std::string& origin,
00476                   const std::string& message = "");
00477     };
00478     class par_file_not_found : public GExceptionHandler {
00479     public:
00480         par_file_not_found(const std::string& origin,
00481                            const std::string& filename,
00482                            const std::string& message = "");
00483     };
00484     class par_file_open_error : public GExceptionHandler {
00485     public:
00486         par_file_open_error(const std::string& origin,
00487                             const std::string& filename,
00488                             const std::string& message = "");
00489     };
00490     class home_not_found : public GExceptionHandler {
00491     public:
00492         home_not_found(const std::string& origin,
00493                        const std::string& message = "");
00494     };
00495     class could_not_create_pfiles : public GExceptionHandler {
00496     public:
00497         could_not_create_pfiles(const std::string& origin,
00498                                 const std::string& home,
00499                                 const std::string& message = "");
00500     };
00501     class pfiles_not_accessible : public GExceptionHandler {
00502     public:
00503         pfiles_not_accessible(const std::string& origin,
00504                               const std::string& home,
00505                               const std::string& message = "");
00506     };
00507     class par_file_syntax_error : public GExceptionHandler {
00508     public:
00509         par_file_syntax_error(const std::string& origin,
00510                               const std::string& home,
00511                               const std::string& message = "");
00512     };
00513     class par_error : public GExceptionHandler {
00514     public:
00515         par_error(const std::string& origin,
00516                   const std::string& name,
00517                   const std::string& message = "");
00518     };
00519     class bad_cmdline_argument : public GExceptionHandler {
00520     public:
00521         bad_cmdline_argument(const std::string& origin,
00522                              const std::string& arg,
00523                              const std::string& message = "");
00524     };
00525 
00526 
00527     // Observation exceptions
00528     class no_response : public GExceptionHandler {
00529     public:
00530         no_response(std::string origin, std::string message = "");
00531     };
00532     class no_roi : public GExceptionHandler {
00533     public:
00534         no_roi(std::string origin, std::string message = "");
00535     };
00536     class no_events : public GExceptionHandler {
00537     public:
00538         no_events(std::string origin, std::string message = "");
00539     };
00540     class no_list : public GExceptionHandler {
00541     public:
00542         no_list(std::string origin, std::string message = "");
00543     };
00544     class no_cube : public GExceptionHandler {
00545     public:
00546         no_cube(std::string origin, std::string message = "");
00547     };
00548     class gradient_par_mismatch : public GExceptionHandler {
00549     public:
00550         gradient_par_mismatch(std::string origin, int nsize, int npars);
00551     };
00552     class caldb_not_found : public GExceptionHandler {
00553     public:
00554         caldb_not_found(std::string origin, std::string home, 
00555                         std::string message = "");
00556     };
00557     class rsp_invalid_type : public GExceptionHandler {
00558     public:
00559         rsp_invalid_type(std::string origin, std::string type,
00560                          std::string message = "");
00561     };
00562     class gti_invalid : public GExceptionHandler {
00563     public:
00564         gti_invalid(std::string origin, GTime tstart, GTime tstop,
00565                     std::string message = "");
00566     };
00567     class erange_invalid : public GExceptionHandler {
00568     public:
00569         erange_invalid(std::string origin, double emin, 
00570                        double emax, std::string message = "");
00571     };
00572     class invalid_statistics : public GExceptionHandler {
00573     public:
00574         invalid_statistics(std::string origin, std::string statistics,
00575                            std::string message = "");
00576     };
00577     class invalid_instrument : public GExceptionHandler {
00578     public:
00579         invalid_instrument(std::string origin, std::string instrument,
00580                            std::string message = "");
00581     };
00582     class time_invalid_unit : public GExceptionHandler {
00583     public:
00584         time_invalid_unit(const std::string& origin,
00585                           const std::string& unit,
00586                           const std::string& message = "");
00587     };
00588     class no_valid_time_ref : public GExceptionHandler {
00589     public:
00590         no_valid_time_ref(const std::string& origin,
00591                           const std::string& message = "");
00592     };
00593 
00594 
00595     // XML exceptions
00596     class xml_syntax_error : public GExceptionHandler {
00597     public:
00598         xml_syntax_error(std::string origin, std::string segment,
00599                          std::string message = "");
00600     };
00601     class xml_attribute_value : public GExceptionHandler {
00602     public:
00603         xml_attribute_value(std::string origin, std::string value);
00604     };
00605     class xml_bad_node_type : public GExceptionHandler {
00606     public:
00607         xml_bad_node_type(std::string origin, std::string type,
00608                           std::string message = "");
00609     };
00610     class xml_name_not_found : public GExceptionHandler {
00611     public:
00612         xml_name_not_found(std::string origin, std::string type,
00613                            std::string message = "");
00614     };
00615     class xml_invalid_parnum : public GExceptionHandler {
00616     public:
00617         xml_invalid_parnum(std::string origin, GXmlElement xml,
00618                            std::string message = "");
00619     };
00620     class xml_invalid_parnames : public GExceptionHandler {
00621     public:
00622         xml_invalid_parnames(std::string origin, GXmlElement xml,
00623                              std::string message = "");
00624     };
00625 
00626 
00627     // Model exceptions
00628     class model_invalid : public GExceptionHandler {
00629     public:
00630         model_invalid(std::string origin, std::string type,
00631                       std::string message = "");
00632     };
00633     class model_invalid_spatial : public GExceptionHandler {
00634     public:
00635         model_invalid_spatial(std::string origin, std::string type,
00636                               std::string message = "");
00637     };
00638     class model_invalid_spectral : public GExceptionHandler {
00639     public:
00640         model_invalid_spectral(std::string origin, std::string type,
00641                                std::string message = "");
00642     };
00643     class model_invalid_temporal : public GExceptionHandler {
00644     public:
00645         model_invalid_temporal(std::string origin, std::string type,
00646                                std::string message = "");
00647     };
00648     class model_invalid_parnum : public GExceptionHandler {
00649     public:
00650         model_invalid_parnum(std::string origin, GXmlElement xml,
00651                              std::string message = "");
00652     };
00653     class model_invalid_parnames : public GExceptionHandler {
00654     public:
00655         model_invalid_parnames(std::string origin, GXmlElement xml,
00656                                std::string message = "");
00657     };
00658     class model_invalid_parvalue : public GExceptionHandler {
00659     public:
00660         model_invalid_parvalue(std::string origin, GXmlElement xml,
00661                                std::string message = "");
00662     };
00663     class model_invalid_parlimit : public GExceptionHandler {
00664     public:
00665         model_invalid_parlimit(std::string origin, GXmlElement xml,
00666                                std::string message = "");
00667     };
00668     class model_invalid_parscale : public GExceptionHandler {
00669     public:
00670         model_invalid_parscale(std::string origin, double scale,
00671                                std::string message = "");
00672         model_invalid_parscale(std::string origin, GXmlElement xml,
00673                                std::string message = "");
00674     };
00675     class file_function_data : public GExceptionHandler {
00676     public:
00677         file_function_data(std::string origin, std::string filename,
00678                            int num, std::string message = "");
00679     };
00680     class file_function_columns : public GExceptionHandler {
00681     public:
00682         file_function_columns(std::string origin, std::string filename,
00683                               int num, std::string message = "");
00684     };
00685     class file_function_value : public GExceptionHandler {
00686     public:
00687         file_function_value(std::string origin, std::string filename,
00688                             double value, std::string message = "");
00689     };
00690     class par_not_found : public GExceptionHandler {
00691     public:
00692         par_not_found(std::string origin, std::string name,
00693                       std::string message = "");
00694     };
00695     class model_not_found : public GExceptionHandler {
00696     public:
00697         model_not_found(std::string origin, std::string name,
00698                         std::string message = "");
00699     };
00700     class no_point_source : public GExceptionHandler {
00701     public:
00702         no_point_source(std::string origin, std::string name,
00703                         std::string message = "");
00704     };
00705     class no_extended_source : public GExceptionHandler {
00706     public:
00707         no_extended_source(std::string origin, std::string name,
00708                            std::string message = "");
00709     };
00710 
00711     // CSV exceptions
00712     class csv_bad_columns : public GExceptionHandler {
00713     public:
00714         csv_bad_columns(std::string origin, std::string filename,
00715                         int rows, int cols, int elements,
00716                         std::string message = "");
00717     };
00718 
00719     // Test exceptions
00720     class test_nested_try_error : public GExceptionHandler {
00721         public:
00722             test_nested_try_error(std::string origin, std::string message = "");
00723     };
00724     
00725     class test_failure : public GExceptionHandler {
00726         public:
00727             test_failure(std::string origin, std::string message = "");
00728     };
00729     
00730     class test_error : public GExceptionHandler {
00731         public:
00732             test_error(std::string origin, std::string message = "");
00733     };
00734 
00735 };
00736 
00737 #endif /* GEXCEPTION_HPP */

Generated on Tue Jan 24 12:37:17 2017 for GammaLib by  doxygen 1.4.7