This is the mail archive of the
libstdc++@sourceware.cygnus.com
mailing list for the libstdc++ project.
Why does vector<>::at() throw range_error?
- To: libstdc++ at sourceware dot cygnus dot com
- Subject: Why does vector<>::at() throw range_error?
- From: <llewelly at 198 dot dsl dot xmission dot com>
- Date: Mon, 24 Jan 2000 17:59:50 -0700
#include <vector>
using std::vector;
#include <iostream>
using std::cout;
#include <stdexcept>
using std::exception;
#include <typeinfo>
int main(void)
{
vector<int> v(10);
try
{
v.at(v.size()+1)=0;
}
catch(exception& e)
{
cout << "Caught " << typeid(e).name() << " .\n";
}
}
/*
This program, when compiled with gcc 2.95.2 and linked against a jan
24 cvs checkout of libstdc++, or libstdc++-2.90.7, shows that
vector<>::at() throws std::range_error:
$g++ -g -Wall -O2 -I/usr/local/libstdc++-cvs/include/g++-v3/ -L/usr/local/libstdc++-cvs/lib vector_at.cc
$a.out
Caught 11range_error .
However, 23.1.1 paragraph 13 says:
# ... at() throws out_of_range if n>= a.size() .
Is this a bug? What is the difference between out_of_range and
range_error?
*/