Udostępnij przez


out_of_range — Klasa

Klasa służy jako klasa bazowa dla wszystkich wyjątków zgłaszanych w celu zgłoszenia argumentu, który jest poza prawidłowym zakresem.

Składnia

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

    explicit out_of_range(const char *message);

};

Uwagi

Wartość zwracana przez what() element jest kopią message.data(). Aby uzyskać więcej informacji, zobacz tematy what oraz data.

Przykład

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

Wymagania

Nagłówek:<stdexcept>

Przestrzeń nazw: std

Zobacz też

logic_error, klasa
Bezpieczeństwo wątku w standardowej bibliotece C++