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
MBDynErrBase(MBDYN_EXCEPT_ARGS_DECL_NODEF)37 MBDynErrBase::MBDynErrBase(MBDYN_EXCEPT_ARGS_DECL_NODEF)
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
Set(const std::string & s)48 MBDynErrBase::Set(const std::string& s)
49 {
50 this->s = s;
51 }
52
53 const char *
what(void) const54 MBDynErrBase::what(void) const throw()
55 {
56 return s.c_str();
57 }
58
59 void
WriteMsg(const char * idx_type,int idx,int imin,int imax,MBDYN_EXCEPT_ARGS_DECL_NODEF)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
ErrIndexOutOfRange(const char * idx_type,int idx,int imin,int imax,MBDYN_EXCEPT_ARGS_DECL_NODEF)71 ErrIndexOutOfRange::ErrIndexOutOfRange(const char *idx_type, int idx, int imin, int imax, MBDYN_EXCEPT_ARGS_DECL_NODEF)
72 : ErrOutOfRange(MBDYN_EXCEPT_ARGS_PASSTHRU)
73 {
74 WriteMsg(idx_type, idx, imin, imax, MBDYN_EXCEPT_ARGS);
75 }
76
ErrIndexOutOfRange(int idx,int imin,int imax,MBDYN_EXCEPT_ARGS_DECL_NODEF)77 ErrIndexOutOfRange::ErrIndexOutOfRange(int idx, int imin, int imax, MBDYN_EXCEPT_ARGS_DECL_NODEF)
78 : ErrOutOfRange(MBDYN_EXCEPT_ARGS_PASSTHRU)
79 {
80 WriteMsg("", idx, imin, imax, MBDYN_EXCEPT_ARGS);
81 }
82
83