I have declared a map like this
map<long long, list<SoundInfo *> > m_soundListMap;
and I also have this function
void addSoundInfo(long long deviceId, SoundInfo * info)
I am trying to add sound info associate with the device id as the key into the map. In this function, I assumed that a key and value pair has been added to the map. So I can retrieve the list of the sound info and add incoming sound info to the back of the list.
I want to catch an exception for the case that the map doesn’t have the key then I can create the key and value pair and insert into the map.
How do I catch this exception in C++?
Thanks in advance…
Depends on how you try to get the item.
Will create an empty list, insert it into the map and return that when the key doesn’t exist yet.
Will return an iterator to the pair that holds both the key and the value, or will be
map::end()if the key doesn’t exist.iter->secondwill be yourlist<SoundInfo*>.