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