stl exceptions 
Author Message
 stl exceptions

hi guys!

i have a dummy question. can i use in stl the exception mechanism like a c++
exceptions? is there any object provided it?

i get a catch(...) exception on the line

mymap[key] = obj;

and i'd like to know, what nature of this exception is. i might be map
exception, and might be copy constructor exception. i'd like to be sure...

thank you.



Wed, 01 Oct 2003 00:22:58 GMT  
 stl exceptions

Quote:
> hi guys!

> i have a dummy question. can i use in stl the exception mechanism like a
c++
> exceptions? is there any object provided it?

> i get a catch(...) exception on the line

> mymap[key] = obj;

> and i'd like to know, what nature of this exception is. i might be map
> exception, and might be copy constructor exception. i'd like to be sure...

catch( const std::exception& e ) {
    std::cout << e.what() << std::endl;

Quote:
}

Sean


Wed, 01 Oct 2003 08:34:34 GMT  
 stl exceptions

Quote:
> > and i'd like to know, what nature of this exception is. i might be map
> > exception, and might be copy constructor exception. i'd like to be
sure...

> catch( const std::exception& e ) {
>     std::cout << e.what() << std::endl;
> }

i don't know why, but that example doesn't work here:

---
typedef vector<int> INTVECTOR;

...
    INTVECTOR iv;
    iv.push_back(12);
    iv.push_back(18);

    try {
        for(long i = 0; i < 10; i++)
            cout << "iv[" << i << "]: " << iv[i] << endl;
    } catch(exception &ee) {
        cout << "exception: " << ee.what() << endl;
    } catch(...) {
        cout << "catch(...)" << endl;
    }
---

output is:

iv[0]: 12
iv[1]: 18
iv[2]: -33686019
iv[3]: 0
iv[4]: 458823
iv[5]: 524544
iv[6]: 3089080
iv[7]: 0
iv[8]: 4362532
iv[9]: 315

there's an explisit out of range, but i got nothing :(

i'm gonna think, that std::exception is only for deriving your own exception
classes. in other words i should create my own class MyVector : vector and
check all the exception situations in my class and wrap them into
std::exception, shouldn't i?

is there any way to get an exception in a such of example at all? is there
any _standard_ mechanism to catch _standard_ exceptions?



Sat, 04 Oct 2003 00:00:45 GMT  
 stl exceptions

Quote:

> is there any way to get an exception in a such of example at all? is there
> any _standard_ mechanism to catch _standard_ exceptions?

Yes. It begins with reading the documentation. <g> vector::operator []
is not required to throw exceptions when passed an index that is out of
bounds. Use vector::at if that's the behavior you want.

--
Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)



Sat, 04 Oct 2003 00:11:44 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. STL exceptions

2. Document of microsoft STL missing exception specification!

3. STL Guru needed (map iterater giving exceptions)

4. Why not using exception handling and stl?

5. Document of microsoft STL missing exception specification!

6. how to detect STL errors or exceptions

7. Using STL without C++ exceptions

8. what exceptions does stl throw

9. exception handling with STL?

10. Catching an Exception in STL!

11. Are memory exceptions thrown from STL?

12. Conflict between VC 7 STL and SGI STL - how to resolve

 

 
Powered by phpBB® Forum Software