MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
except.h
Go to the documentation of this file.
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:
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:
82 };
83 class ErrGeneric : public MBDynErrBase {
84 public:
86 };
87 class ErrInterrupted : public MBDynErrBase {
88 public:
90 };
91 
92 class ErrOutOfRange : public MBDynErrBase {
93 public:
95 };
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 };
104 public:
105  ErrRowIndexOutOfRange(int idx, int imin, int imax, MBDYN_EXCEPT_ARGS_DECL)
106  : ErrIndexOutOfRange("row ", idx, imin, imax, MBDYN_EXCEPT_ARGS_PASSTHRU) {};
107 };
109 public:
110  ErrColIndexOutOfRange(int idx, int imin, int imax, MBDYN_EXCEPT_ARGS_DECL)
111  : ErrIndexOutOfRange("col ", idx, imin, imax, MBDYN_EXCEPT_ARGS_PASSTHRU) {};
112 };
114 public:
116 };
117 class ErrNullNorm : public MBDynErrBase {
118 public:
120 };
121 class ErrMemory : public MBDynErrBase {
122 public:
124 };
125 
126 class EndOfFile : public MBDynErrBase {
127 public:
129 };
130 class ErrFile : public MBDynErrBase {
131 public:
133 };
134 class ErrFileSystem : public MBDynErrBase {
135 public:
137 };
138 
140 public:
142 };
144 public:
146 };
147 
148 #endif /* EXCEPT_H */
149 
ErrFileSystem(const char *file, int line, const char *func, const std::string r=std::string())
Definition: except.h:136
virtual ~MBDynErrBase(void)
Definition: except.h:73
EndOfFile(const char *file, int line, const char *func, const std::string r=std::string())
Definition: except.h:128
ErrOutOfRange(const char *file, int line, const char *func, const std::string r=std::string())
Definition: except.h:94
#define MBDYN_EXCEPT_ARGS_PASSTHRU
Definition: except.h:55
NoErr(const char *file, int line, const char *func, const std::string r=std::string())
Definition: except.h:81
const char * what(void) const
Definition: except.cc:54
void Set(const std::string &s)
Definition: except.cc:48
#define MBDYN_EXCEPT_ARGS_DECL
Definition: except.h:43
ErrNotImplementedYet(const char *file, int line, const char *func, const std::string r=std::string())
Definition: except.h:145
ErrFile(const char *file, int line, const char *func, const std::string r=std::string())
Definition: except.h:132
ErrMemory(const char *file, int line, const char *func, const std::string r=std::string())
Definition: except.h:123
ErrColIndexOutOfRange(int idx, int imin, int imax, const char *file, int line, const char *func, const std::string r=std::string())
Definition: except.h:110
std::string s
Definition: except.h:69
ErrGeneric(const char *file, int line, const char *func, const std::string r=std::string())
Definition: except.h:85
ErrDivideByZero(const char *file, int line, const char *func, const std::string r=std::string())
Definition: except.h:115
Definition: except.h:79
MBDynErrBase(const char *file, int line, const char *func, const std::string r=std::string())
Definition: except.cc:37
ErrNullNorm(const char *file, int line, const char *func, const std::string r=std::string())
Definition: except.h:119
ErrRowIndexOutOfRange(int idx, int imin, int imax, const char *file, int line, const char *func, const std::string r=std::string())
Definition: except.h:105
ErrNotAvailableYet(const char *file, int line, const char *func, const std::string r=std::string())
Definition: except.h:141
ErrInterrupted(const char *file, int line, const char *func, const std::string r=std::string())
Definition: except.h:89