diff --git a/include/pybind11/cast.h b/include/pybind11/cast.h index a4e76aab5..4a0aa3570 100644 --- a/include/pybind11/cast.h +++ b/include/pybind11/cast.h @@ -807,8 +807,14 @@ NAMESPACE_END(detail) template T cast(handle handle) { typedef detail::type_caster::type> type_caster; type_caster conv; - if (!conv.load(handle, true)) - throw cast_error("Unable to cast Python object to C++ type"); + if (!conv.load(handle, true)) { +#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() + "''"); +#endif + } return conv.operator typename type_caster::template cast_op_type(); }