diff --git a/gen_wrap.py b/gen_wrap.py
index 8cca026a5b96b29c74f19a226384b6973500da50..e13fb57c40ec4eade8a8690b37e1c99c399170c2 100644
--- a/gen_wrap.py
+++ b/gen_wrap.py
@@ -982,6 +982,10 @@ def write_method_wrapper(gen, cls_name, meth):
                         raise Error("isl_val_int_from_si failed")
 
                     {val_name} = _instantiate(Val, _cdata_{name})
+
+                else:
+                    raise IslTypeError("{name} is a %s and cannot "
+                        "be cast to a Val" % type({name}))
                 """
                 .format(
                     arg0_name=meth.args[0].name,