For Programmers: Free Programming Magazines  


Home > Archive > VC STL > February 2005 > std::map: clear throws an exception









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author std::map: clear throws an exception
Sujay Ghosh

2005-02-26, 8:59 am

Hi ,

When I am trying to using map::clear to clear my map , I am getting an
exception .

map<long, CMyClass> myMap;

myMap.clear() ; // Clear the map before doing anything new .

Any help would be appreciated .

Thanks .

Sujay




--
Sujay Ghosh
Bangalore, INDIA
Email : sujayg_mfc@yahoo.com
Mobile : 9845467789

Pete Becker

2005-02-26, 8:59 am

Sujay Ghosh wrote:

> Hi ,
>
> When I am trying to using map::clear to clear my map , I am getting an
> exception .
>
> map<long, CMyClass> myMap;
>
> myMap.clear() ; // Clear the map before doing anything new .
>
> Any help would be appreciated .
>


You haven't provided the definition of CMyClass, so it's hard to give a
definitive answer. I tried it with map<long, int> and it worked fine.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Doug Harrison [MVP]

2005-02-26, 4:00 pm

Sujay Ghosh wrote:

>Hi ,
>
> When I am trying to using map::clear to clear my map , I am getting an
>exception .


What's the exception?

> map<long, CMyClass> myMap;
>
> myMap.clear() ; // Clear the map before doing anything new .
>
> Any help would be appreciated .


Any exceptions emanating from clear() are not due to clear() itself. Some
possibilities include:

1. CMyClass's destructor exits via an exception. It's a bad idea to allow an
exception to escape from a dtor, because if it happens during stack
unwinding due to another exception, terminate() will be called.

2. Your program consists of multiple modules, i.e. EXE and DLLs, and not all
modules link to the same CRT DLL. To share C++ objects between modules, you
must link them all to the same CRT DLL. If you're using VC6, there is an
additional problem with <xtree>, which you can fix as described here:

http://www.dinkumware.com/vc_fixes.html

3. You have some other bug in your program. Perhaps CMyClass is
double-deleting an object, or you have a buffer overrun somewhere, etc.

Beyond this, I don't know. You really need to provide a better error
description, including type of exception and compiler version, at the least.

--
Doug Harrison
Microsoft MVP - Visual C++
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com