共用方式為


out_of_range Class

類別會針對所有例外狀況的基底類別 (Base 報告超出其有效範圍的引數。

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

備註

exception Class 所傳回的值是 message.資料的複本。

範例

// out_of_range.cpp
// compile with: /EHsc
#include <string>
#include <iostream>

using namespace std;

int main() {
// out_of_range
   try {
      string str( "Micro" );
      string rstr( "soft" );
      str.append( rstr, 5, 3 );
      cout << str << endl;
   }
   catch ( exception &e ) {
      cerr << "Caught: " << e.what( ) << endl;
   };
}

Output

Caught: invalid string position

需求

Header: <stdexcept>

命名空間: std

請參閱

參考

logic_error Class

在標準 C++ 程式庫中的執行緒安全