共用方式為


length_error Class

類別會針對所有例外狀況的基底類別(Base報告嘗試太長產生要指派的物件。

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

備註

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

範例

// length_error.cpp
// compile with: /EHsc /GR /MDd
#include <vector>
#include <iostream>

using namespace std;

template<class _Ty>
class stingyallocator : public allocator<_Ty>
{
public:
   template <class U>
      struct rebind { typedef stingyallocator<U> other; };
   _SIZT max_size( ) const
   {
         return 10;
   };

};

int main( )
{
   try
   {
      vector<int, stingyallocator< int > > myv;
      for ( int i = 0; i < 11; i++ ) myv.push_back( i );
   }
   catch ( exception &e )
   {
      cerr << "Caught " << e.what( ) << endl;
      cerr << "Type " << typeid( e ).name( ) << endl;
   };
}
  

需求

Header: <stdexcept>

命名空間: std

請參閱

參考

logic_error Class

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