class
std::invalid_argument
<stdexcept>
Invalid argument exception
|  |
|  |
invalid_argument |
This class defines the type of objects thrown as exceptions to report an invalid argument.
This class is designed so that any program, not just the elements of the standard library, can throw it as an exception. The constructor of
bitset (
bitset::bitset) can throw this exception.
It is defined as:
1 2 3 4
|
class invalid_argument : public logic_error {
public:
explicit invalid_argument (const string& what_arg);
};
|
Members
- constructor
- The constructor takes a standard string object as parameter. This value is stored in the object, and its value is used to generate the C-string returned by its inherited member what.
The class inherits the
what member function from
exception, along with its
copy constructor and
assignment operator member functions.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
// invalid_argument example
#include <iostream>
#include <stdexcept>
#include <bitset>
using namespace std;
int main (void) {
try {
// bitset constructor throws an invalid_argument if initialized
// with a string containing characters other than 0 and 1
bitset<5> mybitset (string("01234"));
}
catch (invalid_argument& ia) {
cerr << "Invalid argument: " << ia.what() << endl;
}
return 0;
}
|
Possible output:
Invalid argument: bitset::_M_copy_from_string
|
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
)