blob: 2773f2591759b1638ad82ab022bfee4ee1ec5f75 (
plain)
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
|
#ifndef RDMA_EXCEPTION_H
#define RDMA_EXCEPTION_H
#include <exception>
#include <errno.h>
#include <string.h>
namespace Rdma {
static __thread char s[50];
class Exception : public std::exception {
int err;
public:
Exception(int e) : err(e) {}
int getError() { return err; }
const char* what() const throw() {
return ::strerror_r(err, s, 50);
}
};
inline void THROW_ERRNO() {
throw Rdma::Exception(errno);
}
inline void CHECK(int rc) {
if (rc != 0)
throw Rdma::Exception((rc == -1) ? errno : rc >0 ? rc : -rc);
}
inline void CHECK_IBV(int rc) {
if (rc != 0)
throw Rdma::Exception(rc);
}
template <typename T>
inline
T* CHECK_NULL(T* rc) {
if (rc == 0)
THROW_ERRNO();
return rc;
}
}
#endif // RDMA_EXCEPTION_H
|