首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::ios_base::failure

Defined in header <ios>

?

?

class failure;

?

?

全班std::ios_base::failure定义输入/输出库中的函数在失败时抛出的异常对象。

std::ios_base::failure的成员类可以定义为std::ios_base或者作为同义词%28tydurif%29用于另一个具有同等功能的类。%28自C++17%29。

Inheritance diagram.

(until C++11)

Inheritance diagram.

(since C++11)

成员函数

(constructor)

constructs the exception object (public member function)

科技促进发展:监督办[医]*失败:::失败

explicit failure( const std::string& message );

?

(until C++11)

explicit failure( const std::string& message, const std::error_code& ec = std::io_errc::stream );

?

(since C++11)

explicit failure( const char* message, const std::error_code& ec = std::io_errc::stream );

?

(since C++11)

使用message作为解释字符串,以后可以使用what()...

参数

message

-

explanatory string

继承自STD:系统[医]误差

成员函数

code

returns error code (public member function of std::system_error)

what virtual

returns explanatory string (virtual public member function of std::system_error)

继承自STD::运行时[医]误差

继承自STD:例外

成员函数

(destructor) virtual

destructs the exception object (virtual public member function of std::exception)

what virtual

returns an explanatory string (virtual public member function of std::exception)

二次

代码语言:javascript
复制
#include <iostream>
#include <fstream>
int main()
{
    std::ifstream f("doesn't exist");
    try {
        f.exceptions(f.failbit);
    } catch (const std::ios_base::failure& e)
    {
        std::cout << "Caught an ios_base::failure.\n"
                  << "Explanatory string: " << e.what() << '\n'
                  << "Error code: " << e.code() << '\n';
    }
}

二次

产出:

二次

代码语言:javascript
复制
Caught an ios_base::failure.
Explanatory string: ios_base::clear: unspecified iostream_category error
Error code: iostream:1

二次

另见

io_errc (C++11)

the IO stream error codes (enum)

代码语言:txt
复制
 ? cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com