Commit 472ffbba by Wenzel Jakob

more informative error message when py::cast fails

parent fb0e2e5d
...@@ -807,8 +807,14 @@ NAMESPACE_END(detail) ...@@ -807,8 +807,14 @@ NAMESPACE_END(detail)
template <typename T> T cast(handle handle) { template <typename T> T cast(handle handle) {
typedef detail::type_caster<typename detail::intrinsic_type<T>::type> type_caster; typedef detail::type_caster<typename detail::intrinsic_type<T>::type> type_caster;
type_caster conv; type_caster conv;
if (!conv.load(handle, true)) if (!conv.load(handle, true)) {
throw cast_error("Unable to cast Python object to C++ type"); #if defined(NDEBUG)
throw cast_error("Unable to cast Python instance to C++ type (compile in debug mode for details)");
#else
throw cast_error("Unable to cast Python instance of type " +
(std::string) handle.get_type().str() + " to C++ type '" + type_id<T>() + "''");
#endif
}
return conv.operator typename type_caster::template cast_op_type<T>(); return conv.operator typename type_caster::template cast_op_type<T>();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment