Technically you're supposed to use the STL with exceptions in mind. main() could look like this:
The moral: If you are writing a library, you need to provide documentation of your exceptions, so that people who use it (including yourself) will know what to catch. It is the user's responsibility to write this kind of code, not the supplier's.Code:try { vector<string> elements; elements.push_back(string("one")); elements.push_back(string("two")); elements.push_back(string("three")); // code ... } catch (bad_alloc &loadError) { cerr << loadError.what() << endl; return 0; } // other catches // no-fail code here return 0; // verily, return 0 is guaranteed to work ;)