diff --git a/pyopencl/__init__.py b/pyopencl/__init__.py
index 2e49258586d69cfc38b8298aded86756cb1206db..793b62d69ecec2c08536f1038c40a6e868f89116 100644
--- a/pyopencl/__init__.py
+++ b/pyopencl/__init__.py
@@ -46,8 +46,6 @@ except ImportError:
 
 import numpy as np
 
-from pytools import Record
-
 import sys
 
 _PYPY = '__pypy__' in sys.builtin_module_names
@@ -215,10 +213,6 @@ CONSTANT_CLASSES = tuple(
 
 # {{{ diagnostics
 
-class _ErrorRecord(Record):
-    pass
-
-
 class CompilerWarning(UserWarning):
     pass
 
@@ -524,7 +518,7 @@ class Program(object):
         try:
             return build_func()
         except _cl.RuntimeError as e:
-            msg = e.what
+            msg = str(e)
             if options_bytes:
                 msg = msg + "\n(options: %s)" % options_bytes.decode("utf-8")
 
@@ -542,7 +536,7 @@ class Program(object):
             routine = e.routine
 
             err = _cl.RuntimeError(
-                    _cl.Error._ErrorRecord(
+                    _cl._ErrorRecord(
                         msg=msg,
                         code=code,
                         routine=routine))
@@ -688,17 +682,17 @@ def _add_functionality():
         try:
             self._build(options=options_bytes, devices=devices)
         except Error as e:
-            what = e.what + "\n\n" + (75*"="+"\n").join(
+            msg = str(e) + "\n\n" + (75*"="+"\n").join(
                     "Build on %s:\n\n%s" % (dev, log)
                     for dev, log in self._get_build_logs())
             code = e.code
             routine = e.routine
 
             err = _cl.RuntimeError(
-                    _ErrorRecord(
-                        what=lambda: what,
-                        code=lambda: code,
-                        routine=lambda: routine))
+                    _cl._ErrorRecord(
+                        msg=msg,
+                        code=code,
+                        routine=routine))
 
         if err is not None:
             # Python 3.2 outputs the whole list of currently active exceptions
@@ -1000,7 +994,7 @@ def _add_functionality():
     # {{{ Error
 
     def error_str(self):
-        val = self.args[0]
+        val = self.what
         try:
             val.routine
         except AttributeError:
@@ -1027,7 +1021,7 @@ def _add_functionality():
         return self.args[0].routine()
 
     def error_what(self):
-        return self.args[0].what()
+        return self.args[0]
 
     Error.__str__ = error_str
     Error.code = property(error_code)
diff --git a/src/wrap_cl.hpp b/src/wrap_cl.hpp
index a20f2f0f77003aad2a127e36be99e0b61bc241a1..b2d5877ee1257433aee986c3b8e0e8276314da48 100644
--- a/src/wrap_cl.hpp
+++ b/src/wrap_cl.hpp
@@ -398,15 +398,15 @@ namespace pyopencl
   class error : public std::runtime_error
   {
     private:
-      const char *m_routine;
+      std::string m_routine;
       cl_int m_code;
 
     public:
-      error(const char *rout, cl_int c, const char *msg="")
-        : std::runtime_error(msg), m_routine(rout), m_code(c)
+      error(const char *routine, cl_int c, const char *msg="")
+        : std::runtime_error(msg), m_routine(routine), m_code(c)
       { }
 
-      const char *routine() const
+      const std::string &routine() const
       {
         return m_routine;
       }
diff --git a/src/wrap_constants.cpp b/src/wrap_constants.cpp
index cf004bcf8ae1d27608afaf5d0d2f06fae36a6555..e585e117460840f48b53327ecd8b9adaa3f77899 100644
--- a/src/wrap_constants.cpp
+++ b/src/wrap_constants.cpp
@@ -95,21 +95,30 @@ void pyopencl_expose_constants(py::module &m)
   }
   // }}}
 
-  // {{{ constants
-#define ADD_ATTR(PREFIX, NAME) \
-  cls.attr(#NAME) = CL_##PREFIX##NAME
-#define ADD_ATTR_SUFFIX(PREFIX, NAME, SUFFIX) \
-  cls.attr(#NAME) = CL_##PREFIX##NAME##SUFFIX
+  // {{{ error record
 
   {
     typedef error cls;
-    py::class_<error> (m, "_error")
+    py::class_<error> (m, "_ErrorRecord")
+      .def(py::init<const char *, cl_int, const char *>(),
+          py::arg("routine"),
+          py::arg("code"),
+          py::arg("msg"))
       .DEF_SIMPLE_METHOD(routine)
       .DEF_SIMPLE_METHOD(code)
       .DEF_SIMPLE_METHOD(what)
+      .DEF_SIMPLE_METHOD(is_out_of_memory)
       ;
   }
 
+  // }}}
+
+  // {{{ constants
+#define ADD_ATTR(PREFIX, NAME) \
+  cls.attr(#NAME) = CL_##PREFIX##NAME
+#define ADD_ATTR_SUFFIX(PREFIX, NAME, SUFFIX) \
+  cls.attr(#NAME) = CL_##PREFIX##NAME##SUFFIX
+
   {
     py::class_<status_code> cls(m, "status_code");