! \brief Exception class * * This may be thrown by API functions when CL_HPP_ENABLE_EXCEPTIONS is defined. */
| 747 | * This may be thrown by API functions when CL_HPP_ENABLE_EXCEPTIONS is defined. |
| 748 | */ |
| 749 | class Error : public std::exception |
| 750 | { |
| 751 | private: |
| 752 | cl_int err_; |
| 753 | const char * errStr_; |
| 754 | public: |
| 755 | /*! \brief Create a new CL error exception for a given error code |
| 756 | * and corresponding message. |
| 757 | * |
| 758 | * \param err error code value. |
| 759 | * |
| 760 | * \param errStr a descriptive string that must remain in scope until |
| 761 | * handling of the exception has concluded. If set, it |
| 762 | * will be returned by what(). |
| 763 | */ |
| 764 | Error(cl_int err, const char * errStr = nullptr) : err_(err), errStr_(errStr) |
| 765 | {} |
| 766 | |
| 767 | ~Error() throw() {} |
| 768 | |
| 769 | /*! \brief Get error string associated with exception |
| 770 | * |
| 771 | * \return A memory pointer to the error message string. |
| 772 | */ |
| 773 | virtual const char * what() const throw () |
| 774 | { |
| 775 | if (errStr_ == nullptr) { |
| 776 | return "empty"; |
| 777 | } |
| 778 | else { |
| 779 | return errStr_; |
| 780 | } |
| 781 | } |
| 782 | |
| 783 | /*! \brief Get error code associated with exception |
| 784 | * |
| 785 | * \return The error code. |
| 786 | */ |
| 787 | cl_int err(void) const { return err_; } |
| 788 | }; |
| 789 | #define CL_HPP_ERR_STR_(x) #x |
| 790 | #else |
| 791 | #define CL_HPP_ERR_STR_(x) nullptr |