Skip to content

Latest commit

 

History

History
104 lines (89 loc) · 2.16 KB

File metadata and controls

104 lines (89 loc) · 2.16 KB
title length_error Class | Microsoft Docs
ms.custom
ms.date 11/04/2016
ms.reviewer
ms.suite
ms.technology
cpp-standard-libraries
ms.tgt_pltfrm
ms.topic article
f1_keywords
stdexcept/std::length_error
length_error
dev_langs
C++
helpviewer_keywords
length_error class
ms.assetid d53c46c5-4626-400d-bd76-bf3e1e0f64ae
caps.latest.revision 21
author corob-msft
ms.author corob
manager ghogen
translation.priority.ht
cs-cz
de-de
es-es
fr-fr
it-it
ja-jp
ko-kr
pl-pl
pt-br
ru-ru
tr-tr
zh-cn
zh-tw

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.

Syntax

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

    explicit length_error(const char *message);

};  

Remarks

The value returned by what is a copy of message.data.

Example

// length_error.cpp  
// compile with: /EHsc /GR /MDd  
#include <vector>  
#include <iostream>  
  
using namespace std;  
  
template<class  T>  
class stingyallocator : public allocator< T>  
{  
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;  
   };  
}  
\* Output:   
Caught vector<T> too long  
Type class std::length_error  
*\  

Requirements

Header: <stdexcept>

Namespace: std

See Also

logic_error Class
Thread Safety in the C++ Standard Library