Sdílet prostřednictvím


out_of_range – třída

Třída slouží jako základní třída pro všechny výjimky vyvolané k hlášení argumentu, který je mimo jeho platný rozsah.

Syntaxe

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

    explicit out_of_range(const char *message);

};

Poznámky

Hodnota vrácená what() hodnotou je kopie message.data(). Další informace najdete v tématech what a data.

Příklad

// 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
*/

Požadavky

Header:<stdexcept>

Obor názvů: std

Viz také

logic_error – třída
Bezpečný přístup z více vláken ve standardní knihovně C++