HSDS
Main Page
Namespaces
Data Structures
Files
File List
Globals
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Friends
Macros
include
hsds
exception.hpp
Go to the documentation of this file.
1
7
#if !defined(HSDS_EXCEPTION_H_)
8
#define HSDS_EXCEPTION_H_
9
10
#include <exception>
11
#include <stdexcept>
12
#include <iostream>
13
#include <string>
14
#if !defined(_MSC_VER)
15
#include <stdint.h>
16
#endif // !defined(_MSC_VER)
17
18
#if !defined(HSDS_EXCEPTION_IF)
19
#if defined(_MSC_VER)
20
#define HSDS_EXCEPTION_IF(cond__, message__) if(cond__){ \
21
throw hsds::Exception(message__, __FILE__, __FUNCTION__, __LINE__); \
22
}
23
#else // defined(_MSC_VER)
24
#define HSDS_EXCEPTION_IF(cond__, message__) if(cond__){ \
25
throw hsds::Exception(message__, __FILE__, __func__, __LINE__); \
26
}
27
#endif //defined(_MSC_VER)
28
#endif
29
30
#if !defined(HSDS_DEBUG_IF)
31
#if defined(_DEBUG)
32
#define HSDS_DEBUG_IF(cond__, message__) HSDS_EXCEPTION_IF(cond__, message__)
33
#else // defined(_DEBUG)
34
#define HSDS_DEBUG_IF(cond__, message__)
35
#endif //defined(_DEBUG)
36
#endif
37
38
42
namespace
hsds {
43
49
class
Exception
:
public
std::exception {
50
public
:
51
60
Exception
(
const
std::string& message,
const
char
* filename,
const
char
* func, uint32_t line) :
61
message_(message), filename_(filename), func_(func), line_(line) {
62
63
}
64
68
~Exception
() throw () {
69
70
}
71
77
const
char
*
what
()
const
throw () {
78
return
message_.c_str();
79
}
80
86
const
char
*
getFileName
()
const
{
87
return
filename_;
88
}
89
95
const
char
*
getFunctionName
()
const
{
96
return
func_;
97
}
98
104
const
int
getLineNumber
()
const
{
105
return
line_;
106
}
107
108
friend
std::ostream&
operator<<
(std::ostream& os,
hsds::Exception
& e);
109
110
private
:
111
std::string message_;
112
const
char
* filename_;
113
const
char
* func_;
114
uint32_t line_;
115
};
116
117
std::ostream&
operator<<
(std::ostream& os,
hsds::Exception
& e){
118
os << e.
what
() <<
" at "
<< e.
getFileName
() <<
":"
<< e.
getLineNumber
() << std::endl;
119
return
os;
120
}
121
122
}
123
124
#endif
/* HSDS_EXCEPTION_H_ */
Generated on Sat Feb 28 2015 20:48:22 for HSDS by
1.8.3.1