C++ Stdexcept 库 - invalid_argument
描述
这是一个无效参数异常,此类定义作为异常抛出的对象类型以报告无效参数。
声明
以下是 std::invalid_argument 的声明。
class invalid_argument;
C++11
class invalid_argument;
参数
none
返回值
none
成员
constructor − 这里作为 what_arg 传递的字符串与成员what 返回的值具有相同的内容。
示例
在下面的 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;
}
输出应该是这样的 −
Invalid argument: bitset::_M_copy_from_ptr

