Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

length_error Class

The class serves as the base class for all exceptions thrown to report an attempt to generate an object too long to be specified.

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

The value returned by exception Class is a copy of message.data.

// 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;
   };
}
Caught vector<T> too long
Type class std::length_error

Header: <stdexcept>

Namespace: std

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.