C++ Stdexcept Library - length_error



Description

It is a length error exception and this class defines the type of objects thrown as exceptions to report a length error.

Declaration

Following is the declaration for std::length_error.

class length_error;

C++11

class length_error;

Parameters

none

Return Value

none

Members

constructor − Here the string passed as what_arg has the same content as the value returned by member what.

Example

In below example for std::length_error.

#include <iostream>
#include <stdexcept>
#include <vector>

int main (void) {
   try {
      std::vector<int> myvector;
      myvector.resize(myvector.max_size()+1);
   } catch (const std::length_error& le) {
      std::cerr << "Length error: " << le.what() << '\n';
   }
   return 0;
}

The output should be like this −

Length error: vector::_M_default_append
stdexcept.htm
Advertisements