표준 C ++ 라이브러리에있는 예외 클래스 몇 가지 새로운 C ++ 11

표준 C ++ 라이브러리에 포함 된 예외 클래스는 무엇이며 어떤 용도로 사용해야합니까? 몇 가지 새로운 C ++ 11 예외가 있다는 것을 알고 있지만 그것이 무엇인지, 어디에 있는지 잘 모르겠습니다.



답변

std::exception <exception> interface (debatable if you should catch this)
    std::bad_alloc <new> failure to allocate storage
        std::bad_array_new_length <new> invalid array length
    std::bad_cast <typeinfo> execution of an invalid dynamic-cast
    std::bad_exception <exception> signifies an incorrect exception was thrown
    std::bad_function_call <functional> thrown by "null" std::function
    std::bad_typeid <typeinfo> using typeinfo on a null pointer
    std::bad_weak_ptr <memory> constructing a shared_ptr from a bad weak_ptr
    std::logic_error <stdexcept> errors detectable before the program executes
        std::domain_error <stdexcept> parameter outside the valid range
        std::future_error <future> violated a std::promise/std::future condition
        std::invalid_argument <stdexcept> invalid argument
        std::length_error <stdexcept> length exceeds its maximum allowable size
        std::out_of_range <stdexcept> argument value not in its expected range
    std::runtime_error <stdexcept> errors detectable when the program executes
        std::overflow_error <stdexcept> arithmetic overflow error.
        std::underflow_error <stdexcept> arithmetic underflow error.
        std::range_error <stdexcept> range errors in internal computations
        std::regex_error <regex> errors from the regular expression library.
        std::system_error <system_error> from operating system or other C API
            std::ios_base::failure <ios> Input or output error

출처 : http://en.cppreference.com/w/cpp/error/exception
실제로 대부분의 예외는 logic_error및 에서 파생 된 사용자 지정 예외 runtime_error입니다. 이것이 무시된다는 것은 아니지만 많은 예외가 도메인에 따라 다릅니다.

예외는 누가 그것을 던졌는 지가 아니라 무엇이 잘못되었는지를 반영해야한다는 것을 명심하십시오 . ( “MyProgramException”없음)


답변

사이트 보기

여기에 이미지 설명 입력

Exception               Description
===================================
std::exception          An exception and parent class of all the standard C++ exceptions.
std::bad_alloc          This can be thrown by new.
std::bad_cast           This can be thrown by dynamic_cast.
std::bad_exception      This is useful device to handle unexpected exceptions in a C++ program
std::bad_typeid         This can be thrown by typeid.
std::logic_error        An exception that theoretically can be detected by reading the code.
std::domain_error       This is an exception thrown when a mathematically invalid domain is used
std::invalid_argument   This is thrown due to invalid arguments.
std::length_error       This is thrown when a too big std::string is created
std::out_of_range       This can be thrown by the at method from for example a std::vector and std::bitset<>::operator[]().
std::runtime_error      An exception that theoretically can not be detected by reading the code.
std::overflow_error     This is thrown if a mathematical overflow occurs.
std::range_error        This is occured when you try to store a value which is out of range.
std::underflow_error    This is thrown if a mathematical underflow occurs.


답변