Standard C++ Library Class Reference
Constructs an object of class out_of_range.
runtime_error::runtime_error (const string& what_arg);
Constructs an object of class runtime_error.
range_error::range_error (const string& what_arg);
Constructs an object of class range_error.
overflow_error::overflow_error (const string& what_arg);
Constructs an object of class overflow_error.
Example
//
// exception.cpp
//
#include <iostream.h>
#include <stdexcept>
static void f() { throw runtime_error("a runtime error"); }
int main ()
{
//
// By wrapping the body of main in a try-catch block we can
// be assured that we'll catch all exceptions in the
// exception hierarchy. You can simply catch exception as is
// done below, or you can catch each of the exceptions in
// which you have an interest.
//
try
{
f();
}
catch (const exception& e)
{
cout << "Got an exception: " << e.what() << endl;
}
return 0;
}