A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cplusplus.com/reference/stdexcept/length_error/ below:

class

<stdexcept>

std::length_error

Length error exception


This class defines the type of objects thrown as exceptions to report a length error.

It is a standard exception that can be thrown by programs. Some components of the standard library, such as vector and string also throw exceptions of this type to signal errors resizing.

It is defined as:


1
2
3
4
class length_error : public logic_error {
public:
  explicit length_error (const string& what_arg);
};
1
2
3
4
5
class length_error : public logic_error {
public:
  explicit length_error (const string& what_arg);
  explicit length_error (const char* what_arg);
};

Members
constructor
The string passed as what_arg has the same content as the value returned by member what.

The class inherits the what member function from logic_error.

Example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
// length_error example
#include <iostream>       // std::cerr
#include <stdexcept>      // std::length_error
#include <vector>         // std::vector

int main (void) {
  try {
    // vector throws a length_error if resized above max_size
    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;
}

Possible output:
Length error: vector::_M_fill_insert


Exception safetyStrong guarantee: if the constructor throws an exception, there are no side effects.

See also
exception
Standard exception class (class)
logic_error
Logic error exception (class)
runtime_error
Runtime error exception (class)
domain_error
Domain error exception (class)
invalid_argument
Invalid argument exception (class)
out_of_range
Out-of-range exception (class)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4