diff --git a/src/c_wrapper/wrap_cl.cpp b/src/c_wrapper/wrap_cl.cpp
index 02c2526ef1526c036b8f5d536f1ae42682390661..1c89e94c3c1aacc637e0931e02e71a3a379c31fc 100644
--- a/src/c_wrapper/wrap_cl.cpp
+++ b/src/c_wrapper/wrap_cl.cpp
@@ -463,8 +463,15 @@ namespace pyopencl
   inline std::vector<cl_device_id> platform::get_devices(cl_device_type devtype)
   {
     cl_uint num_devices = 0;
-    PYOPENCL_CALL_GUARDED(clGetDeviceIDs,
-                          (m_platform, devtype, 0, 0, &num_devices));
+    PYOPENCL_PRINT_CALL_TRACE("clGetDeviceIDs");
+    {
+      cl_int status_code;
+      status_code = clGetDeviceIDs(m_platform, devtype, 0, 0, &num_devices);
+      if (status_code == CL_DEVICE_NOT_FOUND)
+        num_devices = 0;
+      else if (status_code != CL_SUCCESS) \
+        throw pyopencl::error("clGetDeviceIDs", status_code);
+    }
 
     std::vector<cl_device_id> devices(num_devices);
     if (num_devices == 0)