Reputation: 2124
Windows.Foundation.Collections
has a collection called PropertySet
which according to MSDN has a lookup
method which returns:
The value, if an item with the specified key exists; otherwise, null.
When I try the following I get an (unexpected) exception:
try
{
auto propertySet = ref new Windows::Foundation::Collections::PropertySet();
auto something = propertySet->Lookup("nothing");
if (something != nullptr)
{
// Something was found :|
}
else
{
// Found nothing :)
}
}catch(Platform::Exception^ e)
{
//Exception: e->Message
}
and e->Message
is:
The operation attempted to access data outside the valid range
I couldn't find anything on MSDN regarding this issue.
Am I doing something wrong here, or is this a Microsoft bug \ wrong documentation?
EDIT:
1- I'm using windows 10 with SDK version 10.0.10240.0
2- I'm using C++/CX, not C# (if this was not clear)
Upvotes: 2
Views: 267
Reputation: 45172
The documentation is incorrect. I will ask for it to be fixed. If the key does not exist, Lookup
raises a Platform::OutOfBoundsException
(internally: E_BOUNDS
). To check whether a key exists, use the HasKey
method.
Upvotes: 4