TITLE: exception safety and STL (Newsgroups: comp.lang.c++.moderated, 7 May 97) WILCOX: wilcoxb@ucsu.Colorado.EDU (Zooko) |> Can you explain what you mean by "exception safe" standard |> libraries? Why do the standard libraries need to handle any |> exceptions? KANZE: James Kanze A simple example: vector. Given a declaration like: vector< MyType > a( 100 ) ; This will cause the copy constructor for MyType to be called 100 times. If one of those times throws an exception, none of the previously constructed objects will be destructed, and the memory will not be freed. Now note that this can happen even in the simplest cases, since operator new may throw. Consider: vector< vector< int > > a2d( 10000 , vector< int >( 10000 ) ) ; On my machine, this is practically guaranteed to throw (since I don't have 400 Megabyte virtual memory configured). But it will only do so after having allocated a lot of the memory I do have, and it will not release this memory. In this regard, it is worth pointing out that Dave Abrahams has implemented exception safety for the STL, and that a version of STL with his implementation is available at http://www.ipmce.su/people/fbp/stl/stlport.html. For the moment, I would strongly recommend using this version (rather than the one which came with your compiler) in production code (and Cay Horstmann's safe STL in your debugging versions).