A RetroSearch Logo

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

Search Query:

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

class

<stdexcept>

std::invalid_argument

Invalid argument exception


This class defines the type of objects thrown as exceptions to report an invalid argument.

It is a standard exception that can be thrown by programs. Some components of the standard library also throw exceptions of this type to signal invalid arguments.

It is defined as:


1
2
3
4
class invalid_argument : public logic_error {
public:
  explicit invalid_argument (const string& what_arg);
};
1
2
3
4
5
class invalid_argument : public logic_error {
public:
  explicit invalid_argument (const string& what_arg);
  explicit invalid_argument (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
17
// invalid_argument example
#include <iostream>       // std::cerr
#include <stdexcept>      // std::invalid_argument
#include <bitset>         // std::bitset
#include <string>         // std::string

int main (void) {
  try {
    // bitset constructor throws an invalid_argument if initialized
    // with a string containing characters other than 0 and 1
    std::bitset<5> mybitset (std::string("01234"));
  }
  catch (const std::invalid_argument& ia) {
	  std::cerr << "Invalid argument: " << ia.what() << '\n';
  }
  return 0;
}

Possible output:
Invalid argument: bitset::_M_copy_from_string


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)
length_error
Length error 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