In the cppwinrt generated header we have this in windows.foundation.collections.0.h, and we go down the first branch in the code, which will throw if the item is not found (in this case, XAML's ResourceDictionary returns E_FAIL):
auto TryLookup(param_type<K> const& key) const
{
if constexpr (std::is_base_of_v<Windows::Foundation::IUnknown, V>)
{
V result{ nullptr };
impl::check_hresult_allow_bounds(WINRT_IMPL_SHIM(Windows::Foundation::Collections::IMap<K, V>)->Lookup(get_abi(key), put_abi(result)));
return result;
}
else
{
std::optional<V> result;
V value{ empty_value<V>() };
if (0 == impl::check_hresult_allow_bounds(WINRT_IMPL_SHIM(Windows::Foundation::Collections::IMap<K, V>)->Lookup(get_abi(key), put_abi(value))))
{
result = std::move(value);
}
return result;
}
}