@@ -505,7 +505,7 @@ struct smart_holder_type_caster_load {
505505 }
506506 if (void_ptr == nullptr ) {
507507 if (have_holder ()) {
508- throw_if_uninitialized_or_disowned_holder ();
508+ throw_if_uninitialized_or_disowned_holder (typeid (T) );
509509 void_ptr = holder ().template as_raw_ptr_unowned <void >();
510510 } else if (load_impl.loaded_v_h .vh != nullptr ) {
511511 void_ptr = load_impl.loaded_v_h .value_ptr ();
@@ -548,7 +548,7 @@ struct smart_holder_type_caster_load {
548548 if (!have_holder ()) {
549549 return nullptr ;
550550 }
551- throw_if_uninitialized_or_disowned_holder ();
551+ throw_if_uninitialized_or_disowned_holder (typeid (T) );
552552 holder_type &hld = holder ();
553553 hld.ensure_is_not_disowned (" loaded_as_shared_ptr" );
554554 if (hld.vptr_is_using_noop_deleter ) {
@@ -612,7 +612,7 @@ struct smart_holder_type_caster_load {
612612 if (!have_holder ()) {
613613 return unique_with_deleter<T, D>(nullptr , std::unique_ptr<D>());
614614 }
615- throw_if_uninitialized_or_disowned_holder ();
615+ throw_if_uninitialized_or_disowned_holder (typeid (T) );
616616 throw_if_instance_is_currently_owned_by_shared_ptr ();
617617 holder ().ensure_is_not_disowned (context);
618618 holder ().template ensure_compatible_rtti_uqp_del <T, D>(context);
@@ -694,17 +694,22 @@ struct smart_holder_type_caster_load {
694694 holder_type &holder () const { return load_impl.loaded_v_h .holder <holder_type>(); }
695695
696696 // have_holder() must be true or this function will fail.
697- void throw_if_uninitialized_or_disowned_holder () const {
697+ void throw_if_uninitialized_or_disowned_holder (const char *typeid_name) const {
698+ static const std::string missing_value_msg = " Missing value for wrapped C++ type `" ;
698699 if (!holder ().is_populated ) {
699- pybind11_fail ( " Missing value for wrapped C++ type: "
700- " Python instance is uninitialized." );
700+ throw value_error (missing_value_msg + clean_type_id (typeid_name)
701+ + " `: Python instance is uninitialized." );
701702 }
702703 if (!holder ().has_pointee ()) {
703- throw value_error (" Missing value for wrapped C++ type: "
704- " Python instance was disowned." );
704+ throw value_error (missing_value_msg + clean_type_id (typeid_name)
705+ + " `: Python instance was disowned." );
705706 }
706707 }
707708
709+ void throw_if_uninitialized_or_disowned_holder (const std::type_info &type_info) const {
710+ throw_if_uninitialized_or_disowned_holder (type_info.name ());
711+ }
712+
708713 // have_holder() must be true or this function will fail.
709714 void throw_if_instance_is_currently_owned_by_shared_ptr () const {
710715 auto vptr_gd_ptr = std::get_deleter<pybindit::memory::guarded_delete>(holder ().vptr );
0 commit comments