[ Web Proxy ]
URL:
Viewing: https://ru.cppreference.com/cpp/error/overflow_error [Back]  [Original]

std::overflow_error cppreference.com
cppreference.com

std::overflow_error

cppreference.com
<tbody> </tbody>
class overflow_error;

, . ( , ).

, , std::bitset::to_ulong.

( C++11)

, , std::bitset::to_ulong std::bitset::to_ullong.

( C++11)

( , math_errhandling). . , boost.math std::overflow_error, boost::math::policies::throw_on_error ( ).

-

()
overflow_error
(public -)
operator=
overflow_error
(public -)

std::overflow_error::overflow_error

<tbody> </tbody> <tbody class="t-dcl-rev t-dcl-rev-num "> </tbody><tbody> </tbody>
overflow_error( const std::string& what_arg );
(1)
overflow_error( const char* what_arg );
(2)
(3)
overflow_error( const overflow_error& other );
( C++11)
overflow_error( const overflow_error& 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::overflow_error, std::strcmp(what(), other.what()) == 0. . ( C++11)

what_arg
other

std::overflow_error , . , std::string&&: .

LWG 254, std::string. std::string.

LWG 471, . , , what(), .

std::overflow_error::operator=

<tbody> </tbody> <tbody class="t-dcl-rev "> </tbody><tbody> </tbody>
overflow_error& operator=( const overflow_error& other );
( C++11)
overflow_error& operator=( const overflow_error& other ) noexcept;
( C++11)

other. *this other std::overflow_error, 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 -) []

#include <iostream>
#include <limits>
#include <stdexcept>
#include <utility>

template <typename T, int N>
    requires (N > 0) /*...*/
class Stack
{
    int top_ { -1 };
    T data_[N];

public:
    [[nodiscard]] bool empty() const { return top_ == -1; }

    void push(T x)
    {
        if (top_ == N - 1)
            throw std::overflow_error(" !");
        data_[++top_] = std::move(x);
    }

    void pop()
    {
        if (empty())
            throw std::underflow_error(" !");
        --top_;
    }

    T const& top() const
    {
        if (empty())
            throw std::overflow_error(" !");
        return data_[top_];
    }
};

int main()
{
    Stack<int, 4> st;

    try
    {
        [[maybe_unused]] auto x = st.top();
    }
    catch (std::overflow_error const& ex)
    {
        std::cout << "1) : " << ex.what() << '\n';
    }

    st.push(1337);
    while (not st.empty())
    	st.pop();

    try
    {
        st.pop();
    }
    catch (std::overflow_error const& ex)
    {
        std::cout << "2) : " << ex.what() << '\n';
    }

    try
    {
        for (int i {}; i != 13; ++i)
            st.push(i);
    }
    catch (std::overflow_error const& ex)
    {
        std::cout << "3) : " << ex.what() << '\n';
    }
}

:

1) :  !
2) :  !
3) :  !

C++:

LWG 254 C++98 , const char*,
LWG 471 C++98 std::overflow_error
,
std::overflow_error

Web Proxy Viewer  |  New URL  |  Original Page