1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/libraries/libmbutil/except.h,v 1.32 2017/01/12 14:44:04 masarati Exp $ */ 2 /* 3 * This library comes with MBDyn (C), a multibody analysis code. 4 * http://www.mbdyn.org 5 * 6 * Copyright (C) 1996-2017 7 * 8 * Pierangelo Masarati <masarati@aero.polimi.it> 9 * 10 * Dipartimento di Ingegneria Aerospaziale - Politecnico di Milano 11 * via La Masa, 34 - 20156 Milano, Italy 12 * http://www.aero.polimi.it 13 * 14 * Changing this copyright notice is forbidden. 15 * 16 * This program is free software; you can redistribute it and/or modify 17 * it under the terms of the GNU General Public License as published by 18 * the Free Software Foundation (version 2 of the License). 19 * 20 * 21 * This program is distributed in the hope that it will be useful, 22 * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 * GNU General Public License for more details. 25 * 26 * You should have received a copy of the GNU General Public License 27 * along with this program; if not, write to the Free Software 28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 29 */ 30 31 #ifndef EXCEPT_H 32 #define EXCEPT_H 33 34 #include <exception> 35 #include <stdio.h> 36 37 #include <iostream> 38 39 // Use this macro instead of the required set of args when declaring the constructor 40 // of classes derived from Err_base 41 #define MBDYN_EXCEPT_ARGS_DECL_NOOPT \ 42 const char *file, int line, const char *func 43 #define MBDYN_EXCEPT_ARGS_DECL \ 44 MBDYN_EXCEPT_ARGS_DECL_NOOPT , const std::string r = std::string() 45 // Use this macro instead of the required set of args when coding, not inline, the constructor 46 // of classes derived from Err_base 47 #define MBDYN_EXCEPT_ARGS_DECL_NOOPT_NODEF \ 48 const char *file, int line, const char *func 49 #define MBDYN_EXCEPT_ARGS_DECL_NODEF \ 50 MBDYN_EXCEPT_ARGS_DECL_NOOPT_NODEF , const std::string r 51 // Use this macro to pass the required set of args thru to Err_base from the constructor 52 // of derived classes 53 #define MBDYN_EXCEPT_ARGS_NOOPT_PASSTHRU \ 54 file, line, func 55 #define MBDYN_EXCEPT_ARGS_PASSTHRU \ 56 MBDYN_EXCEPT_ARGS_NOOPT_PASSTHRU , r 57 // Use this macro to pass the required set of args to error classes derived from Err_base 58 #if __GNUC__ >= 2 59 #define MBDYN_EXCEPT_ARGS \ 60 __FILE__ , __LINE__ , __PRETTY_FUNCTION__ 61 #else // ! __GNUC__ 62 // FIXME: need to detect whether __func__ (C99) is available 63 #define MBDYN_EXCEPT_ARGS \ 64 __FILE__ , __LINE__ , "(unknown)" 65 #endif // ! __GNUC__ 66 67 class MBDynErrBase : public std::exception { 68 private: 69 std::string s; 70 71 public: 72 MBDynErrBase(MBDYN_EXCEPT_ARGS_DECL); ~MBDynErrBase(void)73 virtual ~MBDynErrBase(void) throw() {}; 74 void Set(const std::string& s); 75 const char * what(void) const throw(); 76 }; 77 78 79 class NoErr : public MBDynErrBase { 80 public: NoErr(MBDYN_EXCEPT_ARGS_DECL)81 NoErr(MBDYN_EXCEPT_ARGS_DECL) : MBDynErrBase(MBDYN_EXCEPT_ARGS_PASSTHRU) {}; 82 }; 83 class ErrGeneric : public MBDynErrBase { 84 public: ErrGeneric(MBDYN_EXCEPT_ARGS_DECL)85 ErrGeneric(MBDYN_EXCEPT_ARGS_DECL) : MBDynErrBase(MBDYN_EXCEPT_ARGS_PASSTHRU) {}; 86 }; 87 class ErrInterrupted : public MBDynErrBase { 88 public: ErrInterrupted(MBDYN_EXCEPT_ARGS_DECL)89 ErrInterrupted(MBDYN_EXCEPT_ARGS_DECL) : MBDynErrBase(MBDYN_EXCEPT_ARGS_PASSTHRU) {}; 90 }; 91 92 class ErrOutOfRange : public MBDynErrBase { 93 public: ErrOutOfRange(MBDYN_EXCEPT_ARGS_DECL)94 ErrOutOfRange(MBDYN_EXCEPT_ARGS_DECL) : MBDynErrBase(MBDYN_EXCEPT_ARGS_PASSTHRU) {}; 95 }; 96 class ErrIndexOutOfRange : public ErrOutOfRange { 97 protected: 98 ErrIndexOutOfRange(const char *idx_type, int idx, int imin, int imax, MBDYN_EXCEPT_ARGS_DECL); 99 void WriteMsg(const char *idx_type, int idx, int imin, int imax, MBDYN_EXCEPT_ARGS_DECL); 100 public: 101 ErrIndexOutOfRange(int idx, int imin, int imax, MBDYN_EXCEPT_ARGS_DECL); 102 }; 103 class ErrRowIndexOutOfRange : public ErrIndexOutOfRange { 104 public: ErrRowIndexOutOfRange(int idx,int imin,int imax,MBDYN_EXCEPT_ARGS_DECL)105 ErrRowIndexOutOfRange(int idx, int imin, int imax, MBDYN_EXCEPT_ARGS_DECL) 106 : ErrIndexOutOfRange("row ", idx, imin, imax, MBDYN_EXCEPT_ARGS_PASSTHRU) {}; 107 }; 108 class ErrColIndexOutOfRange : public ErrIndexOutOfRange { 109 public: ErrColIndexOutOfRange(int idx,int imin,int imax,MBDYN_EXCEPT_ARGS_DECL)110 ErrColIndexOutOfRange(int idx, int imin, int imax, MBDYN_EXCEPT_ARGS_DECL) 111 : ErrIndexOutOfRange("col ", idx, imin, imax, MBDYN_EXCEPT_ARGS_PASSTHRU) {}; 112 }; 113 class ErrDivideByZero : public MBDynErrBase { 114 public: ErrDivideByZero(MBDYN_EXCEPT_ARGS_DECL)115 ErrDivideByZero(MBDYN_EXCEPT_ARGS_DECL) : MBDynErrBase(MBDYN_EXCEPT_ARGS_PASSTHRU) {}; 116 }; 117 class ErrNullNorm : public MBDynErrBase { 118 public: ErrNullNorm(MBDYN_EXCEPT_ARGS_DECL)119 ErrNullNorm(MBDYN_EXCEPT_ARGS_DECL) : MBDynErrBase(MBDYN_EXCEPT_ARGS_PASSTHRU) {}; 120 }; 121 class ErrMemory : public MBDynErrBase { 122 public: ErrMemory(MBDYN_EXCEPT_ARGS_DECL)123 ErrMemory(MBDYN_EXCEPT_ARGS_DECL) : MBDynErrBase(MBDYN_EXCEPT_ARGS_PASSTHRU) {}; 124 }; 125 126 class EndOfFile : public MBDynErrBase { 127 public: EndOfFile(MBDYN_EXCEPT_ARGS_DECL)128 EndOfFile(MBDYN_EXCEPT_ARGS_DECL) : MBDynErrBase(MBDYN_EXCEPT_ARGS_PASSTHRU) {}; 129 }; 130 class ErrFile : public MBDynErrBase { 131 public: ErrFile(MBDYN_EXCEPT_ARGS_DECL)132 ErrFile(MBDYN_EXCEPT_ARGS_DECL) : MBDynErrBase(MBDYN_EXCEPT_ARGS_PASSTHRU) {}; 133 }; 134 class ErrFileSystem : public MBDynErrBase { 135 public: ErrFileSystem(MBDYN_EXCEPT_ARGS_DECL)136 ErrFileSystem(MBDYN_EXCEPT_ARGS_DECL) : MBDynErrBase(MBDYN_EXCEPT_ARGS_PASSTHRU) {}; 137 }; 138 139 class ErrNotAvailableYet : public MBDynErrBase { 140 public: ErrNotAvailableYet(MBDYN_EXCEPT_ARGS_DECL)141 ErrNotAvailableYet(MBDYN_EXCEPT_ARGS_DECL) : MBDynErrBase(MBDYN_EXCEPT_ARGS_PASSTHRU) {}; 142 }; 143 class ErrNotImplementedYet : public MBDynErrBase { 144 public: ErrNotImplementedYet(MBDYN_EXCEPT_ARGS_DECL)145 ErrNotImplementedYet(MBDYN_EXCEPT_ARGS_DECL) : MBDynErrBase(MBDYN_EXCEPT_ARGS_PASSTHRU) {}; 146 }; 147 148 #endif /* EXCEPT_H */ 149 150