C++ Stdexcept Library - invalid_argument


Advertisements

Description

It is an invalid argument exception and this class defines the type of objects thrown as exceptions to report an invalid argument.

Declaration

Following is the declaration for std::invalid_argument.

class invalid_argument;

C++11

class invalid_argument;

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::invalid_argument.

#include <iostream>
#include <stdexcept>
#include <bitset>
#include <string>
int main (void) {
   try {
      std::bitset<5> mybitset (std::string("01203040"));
   } catch (const std::invalid_argument& ia) {
      std::cerr << "Invalid argument: " << ia.what() << '\n';
   }
   return 0;
}

The output should be like this −

Invalid argument: bitset::_M_copy_from_ptr
stdexcept.htm
Advertisements