Skip to content

Latest commit

 

History

History
70 lines (55 loc) · 1.51 KB

out-of-range-class.md

File metadata and controls

70 lines (55 loc) · 1.51 KB
description title ms.date f1_keywords helpviewer_keywords ms.assetid
Learn more about: out_of_range Class
out_of_range Class
09/09/2021
stdexcept/std::out_of_range
out_of_range class
d0e14dc0-065e-4666-9ac9-51e52223c503

out_of_range Class

The class serves as the base class for all exceptions thrown to report an argument that is out of its valid range.

Syntax

class out_of_range : public logic_error {
public:
    explicit out_of_range(const string& message);

    explicit out_of_range(const char *message);

};

Remarks

The value returned by what() is a copy of message.data(). For more information, see what and data.

Example

// out_of_range.cpp
// compile with: /EHsc
#include <exception>
#include <iostream>
#include <string>
#include <typeinfo>
using namespace std;

int main()
{
   try
   {
      string str("Micro");
      string rstr("soft");
      str.append(rstr, 5, 3);
      cout << str << endl;
   }
   catch (const exception& e)
   {
      cerr << "Caught: " << e.what() << endl;
      cerr << "Type: " << typeid(e).name() << endl;
   }
}
/* Output:
Caught: invalid string position
Type: class std::out_of_range
*/

Requirements

Header: <stdexcept>

Namespace: std

See also

logic_error Class
Thread Safety in the C++ Standard Library