MBDyn-1.7.3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups
except.cc
Go to the documentation of this file.
1 /* $Header: /var/cvs/mbdyn/mbdyn/mbdyn-1.0/libraries/libmbutil/except.cc,v 1.12 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 #include "mbconfig.h" /* This goes first in every *.c,*.cc file */
32 
33 #include <sstream>
34 
35 #include "except.h"
36 
38 {
39  std::stringstream ss;
40  ss << "[" << file << ":" << line << ",func=" << func << "]";
41  if (!r.empty()) {
42  ss << " (" << r << ")";
43  }
44  s = ss.str();
45 }
46 
47 void
48 MBDynErrBase::Set(const std::string& s)
49 {
50  this->s = s;
51 }
52 
53 const char *
54 MBDynErrBase::what(void) const throw()
55 {
56  return s.c_str();
57 }
58 
59 void
60 ErrIndexOutOfRange::WriteMsg(const char *idx_type, int idx, int imin, int imax, MBDYN_EXCEPT_ARGS_DECL_NODEF)
61 {
62  std::stringstream ss;
63  ss << "[" << file << ":" << line << ",func=" << func << "]";
64  if (!r.empty()) {
65  ss << " (" << r << ")";
66  }
67  ss << ": " << idx_type << "index=" << idx << " out of range (" << imin << ":" << imax << ")";
68  Set(ss.str());
69 }
70 
71 ErrIndexOutOfRange::ErrIndexOutOfRange(const char *idx_type, int idx, int imin, int imax, MBDYN_EXCEPT_ARGS_DECL_NODEF)
73 {
74  WriteMsg(idx_type, idx, imin, imax, MBDYN_EXCEPT_ARGS);
75 }
76 
79 {
80  WriteMsg("", idx, imin, imax, MBDYN_EXCEPT_ARGS);
81 }
82 
#define MBDYN_EXCEPT_ARGS
Definition: except.h:63
#define MBDYN_EXCEPT_ARGS_PASSTHRU
Definition: except.h:55
const char * what(void) const
Definition: except.cc:54
void Set(const std::string &s)
Definition: except.cc:48
void func(const T &u, const T &v, const T &w, doublereal e, T &f)
#define MBDYN_EXCEPT_ARGS_DECL_NODEF
Definition: except.h:49
static char * file
Definition: ann_in.c:101
void WriteMsg(const char *idx_type, int idx, int imin, int imax, const char *file, int line, const char *func, const std::string r=std::string())
Definition: except.cc:60
ErrIndexOutOfRange(const char *idx_type, int idx, int imin, int imax, const char *file, int line, const char *func, const std::string r=std::string())
Definition: except.cc:71
std::string s
Definition: except.h:69
MBDynErrBase(const char *file, int line, const char *func, const std::string r=std::string())
Definition: except.cc:37