#ifndef CLBLAST_CXPP11_COMMON_H_ #define CLBLAST_CXPP11_COMMON_H_ // C++ #include // std::string #include // std::runtime_error namespace clblast { // ================================================================================================= // Basic exception class: represents an error happened inside our code // (as opposed to an error in C++ runtime) template class Error : public Base { public: using Base::Base; }; // ================================================================================================= // Represents a generic device-specific runtime error (returned by an OpenCL or CUDA API function) class DeviceError : public Error { public: using Error::Error; static std::string TrimCallString(const char *where) { const char *paren = strchr(where, '('); if (paren) { return std::string(where, paren); } else { return std::string(where); } } }; // ================================================================================================= // Represents a generic runtime error (aka environmental problem) class RuntimeError : public Error { public: explicit RuntimeError(const std::string &reason): Error("Run-time error: " + reason) { } }; // ================================================================================================= // Represents a generic logic error (aka failed assertion) class LogicError : public Error { public: explicit LogicError(const std::string &reason): Error("Internal logic error: " + reason) { } }; // ================================================================================================= // Internal exception base class with a status field and a subclass-specific "details" field // which can be used to recreate an exception template class ErrorCode : public Base { public: ErrorCode(Status status, const std::string &details, const std::string &reason): Base(reason), status_(status), details_(details) { } Status status() const { return status_; } const std::string& details() const { return details_; } private: const Status status_; const std::string details_; }; // ================================================================================================= } // namespace clblast // CLBLAST_CXPP11_COMMON_H_ #endif