Archived

This topic is now archived and is closed to further replies.

std::vector's out_of_range exception

This topic is 5311 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

According to Stroustrup''s "The C++ Programming Language", the function std::vector::at() (used for accessing an item of the vector with checking the range of the subscript) should throw an out_of_range exception if the argument is outside the vector''s range (chapter 16.3.3). However, the following code, which is basically what Stroustrup does in his book, too, doesn''t work for me:
try
{
  newMod = runningMods.at(modNum);
}
catch(out_of_range)
{
  // ...

}
where runningMods is a std::vector. I get the error:
parse error before `)'' token 
which basically means that the compiler knows no such thing as "out_of_range". Of course, I have included to be able to use it at all. I have also tried std::out_of_range, without success. Why is this?
My Wonderful Web Site (C++ SDL OpenGL Game Programming)
I am a signature virus. Please add me to your signature so that I may multiply.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
#include <stdexcept>
#screw <c++>
#it <stinks>

Share this post


Link to post
Share on other sites