home *** CD-ROM | disk | FTP | other *** search
Text File | 1998-06-15 | 1.2 KB | 55 lines | [TEXT/CWIE] |
- // STL6.cp
- #include <iostream>
- #include <deque>
- using namespace std;
- /*
-
- The exception hierarchy:
-
- exception root of all exceptions
- | |
- | bad_alloc memory allocation exception
- |
- logic_error precondition violation exception root
- | | |
- | | out_of_range attempt to reference a container
- | | using an illegal index
- | |
- | length_error attempt to create a string with an
- | illegal length
- |
- invalid_argument attempt ot create a container with an
- illegal size such as -1
- */
-
- int main()
- {
- const int limit = 10;
- vector<int> v;
- for (int j = 0; j < limit; ++j)
- {
- v.push_back(j);
- }
- try
- {
- int i = v[limit];
- cout << i << " no exception for i = v[limit];" << endl;
- i = v.at(limit);
- cout << i << " no exception i = v.at(limit);" << endl;
- i = v.at(limit + 1);
- cout << i << " no exception i = v.at(limit + 1);" << endl;
- }
- catch (out_of_range& error)
- {
- cout << "An out of range execption was caught" << endl;
- }
- }
- // CW Pro 1 output
- // 1868783980 no exception for i = v[limit];
- // 1868783980 no exception i = v.at(limit);
- // An out of range execption was caught
-
- // CW Pro 3 output
- // -8 no exception for i = v[limit];
- // An out of range execption was caught
-