length_error 类

类用作。所有引发的异常的基类。报告尝试太长生成将指定的对象。

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

备注

exception 类 返回的值为 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;
   };
}
  

要求

页眉:<stdexcept>

命名空间: std

请参见

参考

logic_error 类

C++ 标准库中的线程安全