std::invalid_argument
cppreference.com
<tbody>
</tbody>
class invalid_argument; |
||
, . , - , .
std::bitset::bitset std::stoi std::stof.
-
() |
invalid_argument (public -) |
operator= |
invalid_argument (public -) |
std::invalid_argument::invalid_argument
<tbody> </tbody> <tbody class="t-dcl-rev t-dcl-rev-num "> </tbody><tbody> </tbody> invalid_argument( const std::string& what_arg ); |
(1) | |
invalid_argument( const char* what_arg ); |
(2) | |
| (3) | ||
invalid_argument( const invalid_argument& other ); |
( C++11) | |
invalid_argument( const invalid_argument& other ) noexcept; |
( C++11) | |
1)
what_arg . std::strcmp(what(), what_arg.c_str()) == 0.2)
what_arg . std::strcmp(what(), what_arg) == 0.3) .
*this other std::invalid_argument, std::strcmp(what(), other.what()) == 0. . ( C++11)| what_arg | ||
| other |
1,2) std::bad_alloc.
std::invalid_argument , . , std::string&&: .
LWG 254, std::string. std::string.
LWG 471, . , , what(), .
std::invalid_argument::operator=
<tbody> </tbody> <tbody class="t-dcl-rev "> </tbody><tbody> </tbody> invalid_argument& operator=( const invalid_argument& other ); |
( C++11) | |
invalid_argument& operator=( const invalid_argument& other ) noexcept; |
( C++11) | |
other. *this other std::invalid_argument, std::strcmp(what(), other.what()) == 0 . . ( C++11)
| other |
*this
LWG 471, . , , what(), .
std::exception
-
[virtual] |
(virtual public of std::exception -)
|
[virtual] |
(virtual public of std::exception -)
|
std::errc::invalid_argument ( std::system_error - std::thread) errno EINVAL.
#include <bitset>
#include <iostream>
#include <stdexcept>
#include <string>
int main()
{
try
{
std::bitset<4>{"012"}; // : '0' '1'
}
catch (std::invalid_argument const& ex)
{
std::cout << "#1: " << ex.what() << '\n';
}
try
{
[[maybe_unused]] int f = std::stoi("ABBA"); // : no conversion
}
catch (std::invalid_argument const& ex)
{
std::cout << "#2: " << ex.what() << '\n';
}
try
{
[[maybe_unused]] float f = std::stof("(3.14)"); // : no conversion
}
catch (std::invalid_argument const& ex)
{
std::cout << "#3: " << ex.what() << '\n';
}
}
:
#1: bitset string ctor has invalid argument
#2: stoi: no conversion
#3: stof: no conversion
C++:
| LWG 254 | C++98 | , const char*,
|
|
| LWG 471 | C++98 | std::invalid_argument |
, std::invalid_argument
|