JayBeams  0.1
Another project to have fun coding.
error.hpp
Go to the documentation of this file.
1 #ifndef jb_clfft_error_hpp
2 #define jb_clfft_error_hpp
3 
4 #include <boost/compute/exception/opencl_error.hpp>
5 #include <stdexcept>
6 
7 namespace jb {
8 namespace clfft {
9 
10 /**
11  * A run-time clFFT error.
12  *
13  * This class represents an error return a clFFT function.
14  */
15 class clfft_error : public std::runtime_error {
16 public:
17  /// Constructor from a clFFT error code and a message
18  clfft_error(cl_int error, char const* msg);
19 
20  /// Destructor
21  ~clfft_error() noexcept {
22  }
23 
24  /// Returns the numeric error code.
25  cl_int error_code() const noexcept {
26  return error_;
27  }
28 
29  /// Convert error code to a string
30  static std::string to_string(cl_int error);
31 
32 private:
33  /// Generate a what() string given an error code and message
34  std::string to_what(cl_int error, char const* msg);
35 
36 private:
37  cl_int error_;
38  std::string what_;
39 };
40 
41 /**
42  * Check in an OpenCL error code is really an error and raise an
43  * exception if so.
44  */
45 inline void check_error_code(cl_int err, char const* msg) {
46  if (err == CL_SUCCESS) {
47  return;
48  }
49  throw jb::clfft::clfft_error(err, msg);
50 }
51 
52 } // namespace clfft
53 } // namespace jb
54 
55 #endif // jb_cl_error_hpp
void check_error_code(cl_int err, char const *msg)
Check in an OpenCL error code is really an error and raise an exception if so.
Definition: error.hpp:45
std::string to_what(cl_int error, char const *msg)
Generate a what() string given an error code and message.
Definition: error.cpp:50
std::string what_
Definition: error.hpp:38
A run-time clFFT error.
Definition: error.hpp:15
~clfft_error() noexcept
Destructor.
Definition: error.hpp:21
static std::string to_string(cl_int error)
Convert error code to a string.
Definition: error.cpp:13
cl_int error_code() const noexcept
Returns the numeric error code.
Definition: error.hpp:25
clfft_error(cl_int error, char const *msg)
Constructor from a clFFT error code and a message.
Definition: error.cpp:8
The top-level namespace for the JayBeams library.
Definition: as_hhmmss.hpp:7