00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef RDMA_EXCEPTION_H
00022 #define RDMA_EXCEPTION_H
00023
00024 #include <exception>
00025
00026 #include <errno.h>
00027 #include <string.h>
00028
00029 namespace Rdma {
00030 static __thread char s[50];
00031 class Exception : public std::exception {
00032 int err;
00033
00034 public:
00035 Exception(int e) : err(e) {}
00036 int getError() { return err; }
00037 const char* what() const throw() {
00038 return ::strerror_r(err, s, 50);
00039 }
00040 };
00041
00042 inline void THROW_ERRNO() {
00043 throw Rdma::Exception(errno);
00044 }
00045
00046 inline void CHECK(int rc) {
00047 if (rc != 0)
00048 throw Rdma::Exception((rc == -1) ? errno : rc >0 ? rc : -rc);
00049 }
00050
00051 inline void CHECK_IBV(int rc) {
00052 if (rc != 0)
00053 throw Rdma::Exception(rc);
00054 }
00055
00056 template <typename T>
00057 inline
00058 T* CHECK_NULL(T* rc) {
00059 if (rc == 0)
00060 THROW_ERRNO();
00061 return rc;
00062 }
00063 }
00064
00065 #endif // RDMA_EXCEPTION_H