This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: exception out_of_range


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;
    }
  }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]