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 declared the following method: private void mockInvokeDBHandler(Map<String, Object>... rows) { List<Map<String, Object>>
I have two classes declared like this: class Object1 { protected ulong guid; protected
I have a std::map declared thusly in a legacy MFC application: typedef std::map<long, CNutrientInfo>
I have a declaration like this #include Output/PtPathWriter.h // class PtPathWriter // I've also
I have something like this: #include <iostream> #include <map> int main() { std::map<int, int*>
This is a contrived example, but lets say I have declared objects: CustomObj fooObj;
I have this scenario, can anybody fill the gaps for me? Its like this:
Supposed I have a type I'll call NamedNestedMap std::map<std::string, std::map<std::string, NamedNestedMap> > In this
I have a question. First, I declared a map: Map<TwoIntClass, Set<Integer>> m = new
What I would like to do is have a map that maps integer keys

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.