共用方式為


out_of_range 類別

此類別可做為擲回之所有例外狀況的基底類別,這些例外狀況報告引數超出其有效範圍。

語法

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

    explicit out_of_range(const char *message);

};

備註

what() 回的值是 的 message.data() 複本。 如需詳細資訊,請參閱 whatdata

範例

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

需求

Header: < stdexcept>

命名空間:std

另請參閱

logic_error 類別
C++ 標準程式庫中的執行緒安全