This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: exception out_of_range
- From: LLeweLLyn Reese <llewelly at lifesupport dot shutdown dot com>
- To: MR <nimrod dot bm at optusnet dot com dot au>
- Cc: gcc-help at gcc dot gnu dot org
- Date: 14 Jun 2003 08:10:19 -0700
- Subject: Re: exception out_of_range
- References: <a05200f01bafc237adc66@[156.40.68.105]><3ED7D72C.4050001@moene.indiv.nluug.nl><1054432019.2301.4.camel@nimrod>
MR <nimrod.bm@optusnet.com.au> writes:
> Hi All,
>
> simple question.
>
> I read that out_of_range is meant to be a system defined type.
std::out_of_range is not a system defined type. It is a standard C++
library defined type. It is in the header <stdexcept> .
> I am trying to use it in some exception handling, but am
> being told it is undeclared. What should I be #include'ing to
> get this defined?
#include<stdexcept>
#include<iostream>
#include<ostream>
void foo()
{
throw std::out_of_range("foo");
}
int main()
{
try
{
foo();
}
catch(std::out_of_range& o)
{
std::cout << "Caught out_of_range: " << o.what() << std::endl;
}
}