Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6060741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:51:35+00:00 2026-05-23T08:51:35+00:00

I have declared a map like this map<long long, list<SoundInfo *> > m_soundListMap; and

  • 0

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…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:51:35+00:00Added an answer on May 23, 2026 at 8:51 am

    What is going to happen if I try to get the list and the map doesn’t have the key?

    Depends on how you try to get the item.

    list<SoundInfo*>& info_list = m_soundListMap[55];
    

    Will create an empty list, insert it into the map and return that when the key doesn’t exist yet.

    typedef map<long long, list<SoundInfo *> >::iterator iterator;
    iterator iter = m_soundListMap.find(55);
    

    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->second will be your list<SoundInfo*>.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have my map declared in xaml like this: <my:Map Height=497 CredentialsProvider=key HorizontalAlignment=Left Margin=6,104,0,0
I have code like this: val dm = List[String]() val dk = List[Map[String,Object]]() .....
I have declared the following method: private void mockInvokeDBHandler(Map<String, Object>... rows) { List<Map<String, Object>>
I have a std::map called 'prompts' which is declared like this: std::map<const int, wstring,
I have a map declared as follows: map < string , list < string
I have a spring map declare in the application context xml like this: <map>
I have something like this: #include <iostream> #include <map> int main() { std::map<int, int*>
I have a std::map declared thusly in a legacy MFC application: typedef std::map<long, CNutrientInfo>
I have a Grails 1.3.7 domain class that is declared like this: class Document
I have a declaration like this #include Output/PtPathWriter.h // class PtPathWriter // I've also

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.