-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexcept.h
More file actions
162 lines (128 loc) · 3.71 KB
/
except.h
File metadata and controls
162 lines (128 loc) · 3.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*******************************************************************
*
* DESCRIPTION: exceptions definition
* class InvalidModelIdException
* class InvalidMessageException
* class MException (base class)
*
* AUTHOR: Amir Barylko & Jorge Beyoglonian
* Version 2: Daniel A. Rodriguez
*
* EMAIL: mailto://amir@dc.uba.ar
* mailto://jbeyoglo@dc.uba.ar
* mailto://drodrigu@dc.uba.ar
*
* DATE: 27/6/1998
* DATE: 27/2/1999 (v2)
*
*******************************************************************/
#ifndef _MEXCEPT_HPP
#define _MEXCEPT_HPP
/** include files **/
#include <list>
#include <iostream>
#include <cstdlib>
#include "stringp.h" // operator +( const std::string &, int ) ;
/** definitions **/
#define MEXCEPTION_LOCATION() ( std::string("File: ") + __FILE__ + " - Method: " + __FUNCTION__ + " - Line: " + __LINE__ )
#define MASSERT(lexp) if( !( lexp ) ) { AssertException e( "Invalid assertion" ) ; e.addText( #lexp ) ; e.addLocation( MEXCEPTION_LOCATION() ) ; throw e ; }
#define MASSERTMSG(lexp,text) if( !( lexp ) ) { AssertException e( "Invalid assertion" ) ; e.addText( #lexp ) ; e.addText( text ) ; e.addLocation( MEXCEPTION_LOCATION() ) ; throw e ; }
#define MASSERT_ERR(str) { std::cout << str; exit(-1); }
#define MTHROW( e ) e.addLocation( MEXCEPTION_LOCATION() ) ; throw e ;
class MException
{
public:
// ** Constructors ** //
MException( const std::string &description = "" )
: descr( description )
{}
MException( const MException & ) ;
virtual ~MException() ;
const std::string &description() const
{return descr;}
MException &addText( const std::string & ) ;
MException &addLocation( const std::string & ) ;
typedef std::list< std::string > TextList ;
typedef std::list< std::string > LocationList ;
const TextList &textList() const
{return texts;}
const LocationList &locationList() const
{return locations;}
std::ostream &print( std::ostream & ) const ;
virtual const std::string type() const
{return "MException";}
private:
std::string descr ;
TextList texts ;
LocationList locations ;
}; // MException
class AssertException: public MException
{
public:
// ** Constructors ** //
AssertException( const std::string &description = ""): MException( description )
{};
const std::string type() const
{return "AssertException";}
}; // AssertException
class InvalidMessageException: public MException
{
public:
const std::string type() const
{return "InvalidMessageException";}
}; // InvalidMessageException
class InvalidModelIdException: public MException
{
public:
const std::string type() const
{return "InvalidModelIdException";}
}; // InvalidModelIdException
class InvalidProcessorIdException: public MException
{
public:
const std::string type() const
{return "InvalidProcessorIdException";}
}; // InvalidProcessorIdException
class InvalidAtomicTypeException: public MException
{
public:
const std::string type() const
{return "InvalidAtomicTypeException";}
}; // InvalidAtomicTypeException
class InvalidPortRequest: public MException
{
public:
const std::string type() const
{return "InvalidPortRequest";}
}; // InvalidPortRequest
/********************/
/** inline methods **/
/********************/
inline
MException::MException( const MException &me )
: descr( me.description() )
, texts( me.texts )
, locations( me.locations )
{}
inline
MException::~MException()
{}
inline
MException &MException::addText( const std::string &str )
{
texts.push_back( str ) ;
return *this ;
}
inline
MException &MException::addLocation( const std::string &str )
{
locations.push_back( str ) ;
return *this ;
}
inline
std::ostream &operator << (std::ostream &os, const MException &e)
{
e.print( os ) ;
return os ;
}
#endif // _MEXCEPT_HPP