boost.png (6897 bytes) System 庫
Boost Home    Library Home   Tutorial   Reference
Contents 目錄
Introduction 簡介
Macros 宏
Deprecated names 不再使用的名字
Header 頭文件 <boost/system/error_code.hpp>
Class error_category
   Class error_category synopsis 概要
   Class error_category virtual members 虛擬成員
   Class error_category non-virtual members 非虛擬成員
   Class error_category non-member functions 非成員函數
   Class error_category predefined objects 預定義對像
Class error_code
   Class error_code synopsis 概要
   Class error_code constructors 構造函數
   Class error_code modifiers 修改器
   Class error_code observers 觀察器
Class error_condition
   Class error_condition synopsis 概要
   Class error_condition constructors 構造函數
   Class error_condition modifiers 修改器
   Class error_condition observers 觀察器
throws 對像
throws 對象的語義
Non-member functions 非成員函數
Header 頭文件 <boost/system/system_error.hpp>
   Class system_error

Introduction 簡介

This reference documentation describes components that  programs may use to report error conditions originating from the operating system or other low-level application program interfaces.

本參考文檔描述了程序員可能用於報告由操作系統或其它底層API所產生的錯誤條件的組件。

Boost.System library components never change the value of errno.

Boost.System 庫的組件不會修改 errno 的值。

Macros 宏

Users may defined the following macros if desired. Sensible defaults are provided, so users may ignore these macros if they prefer.

如果需要,用戶可以定義以下宏。庫提供了合適的缺省值,所以只有用戶願意,也可以忽略這些宏。

Macro Name 宏名 Default 缺省值 Effect if defined 定義後的作用
BOOST_WINDOWS_API Defined if Windows is detected by Boost.System's automatic configuration code, otherwise not defined.
如果 Boost.System 的自動配置代碼檢測出系統為 Windows,則定義該宏,否則不定義。
Implementation uses the Microsoft Windows native application program interface (API).
具體實現使用 Microsoft Windows 的原生API。
BOOST_POSIX_API Defined if Windows is not detected by Boost.System's automatic configuration code.
如果 Boost.System 的自動配置代碼檢測出系統不是 Windows,則定義該宏。
Implementation uses the POSIX native application program interface (API).
具體實現使用 POSIX 原生API。
BOOST_SYSTEM_DYN_LINK Defined if BOOST_ALL_DYN_LINK is defined, otherwise not defined.
如果定義了 BOOST_ALL_DYN_LINK,則定義該宏,否則不定義。
Boost.System library is dynamically linked. If not defined, static linking is assumed.
Boost.System 庫將動態鏈接的。如果未定義該宏,則假設是靜態鏈接。
BOOST_SYSTEM_NO_LIB Defined if BOOST_ALL_NO_LIB is defined, otherwise not defined.
如果定義了 BOOST_ALL_NO_LIB,則定義該宏,否則不定義。
Boost.System library does not use the Boost auto-link facility.
Boost.System 庫不使用 Boost 的自動鏈接工具。
BOOST_SYSTEM_NO_DEPRECATED Not defined.
不定義。
Deprecated features are excluded.
將不建議使用的特性排除在外。

Deprecated names 不再使用的名字

In the process of adding Boost.System to C++0x standard library, some of the names are being changed. To ease transition, Boost.System deprecates the old names, but continues to provide them unless macro BOOST_SYSTEM_NO_DEPRECATED is defined.
在將 Boost.System 增加到 C++0x 標準庫的過程中,有些名字發生了變化。為了易於轉變,Boost.System 不建議再使用舊的名字,不過會繼續提供它們,除非定義了宏 BOOST_SYSTEM_NO_DEPRECATED

Old name, now deprecated
舊名字,現已不再使用
New name
新名字
namespace posix namespace errc
namespace posix_error namespace errc
enum posix_errno enum errc_t
get_posix_category() get_generic_category()
posix_category generic_category
errno_ecat generic_category
native_ecat system_category

Header 頭文件 <boost/system/error_code.hpp>

<boost/system/error_code.hpp> synopsis 概要

namespace boost
{
namespace system
{
class error_category;
class error_code;
class error_condition;

// "Concept" helpers
template< class T="" >
struct is_error_code_enum { static const bool value = false; };

template< class T="" >
struct is_error_condition_enum { static const bool value = false; };

// generic error_conditions
namespace errc
{
enum errc_t
{
success = 0,
address_family_not_supported, //EAFNOSUPPORT
address_in_use, //EADDRINUSE
address_not_available, //EADDRNOTAVAIL
already_connected, //EISCONN
argument_list_too_long, //E2BIG
argument_out_of_domain, //EDOM
bad_address, //EFAULT
bad_file_descriptor, //EBADF
bad_message, //EBADMSG
broken_pipe, //EPIPE
connection_aborted, //ECONNABORTED
connection_already_in_progress, //EALREADY
connection_refused, //ECONNREFUSED
connection_reset, //ECONNRESET
cross_device_link, //EXDEV
destination_address_required, //EDESTADDRREQ
device_or_resource_busy, //EBUSY
directory_not_empty, //ENOTEMPTY
executable_format_error, //ENOEXEC
file_exists, //EEXIST
file_too_large, //EFBIG
filename_too_long, //ENAMETOOLONG
function_not_supported, //ENOSYS
host_unreachable, //EHOSTUNREACH
identifier_removed, //EIDRM
illegal_byte_sequence, //EILSEQ
inappropriate_io_control_operation,//ENOTTY
interrupted, //EINTR
invalid_argument, //EINVAL
invalid_seek, //ESPIPE
io_error, //EIO
is_a_directory, //EISDIR
message_size, //EMSGSIZE
network_down, //ENETDOWN
network_reset, //ENETRESET
network_unreachable, //ENETUNREACH
no_buffer_space, //ENOBUFS
no_child_process, //ECHILD
no_link, //ENOLINK
no_lock_available, //ENOLCK
no_message_available, //ENODATA
no_message, //ENOMSG
no_protocol_option, //ENOPROTOOPT
no_space_on_device, //ENOSPC
no_stream_resources, //ENOSR
no_such_device_or_address, //ENXIO
no_such_device, //ENODEV
no_such_file_or_directory, //ENOENT
no_such_process, //ESRCH
not_a_directory, //ENOTDIR
not_a_socket, //ENOTSOCK
not_a_stream, //ENOSTR
not_connected, //ENOTCONN
not_enough_memory, //ENOMEM
not_supported, //ENOTSUP
operation_canceled, //ECANCELED
operation_in_progress, //EINPROGRESS
operation_not_permitted, //EPERM
operation_not_supported, //EOPNOTSUPP
operation_would_block, //EWOULDBLOCK
owner_dead, //EOWNERDEAD
permission_denied, //EACCES
protocol_error, //EPROTO
protocol_not_supported, //EPROTONOSUPPORT
read_only_file_system, //EROFS
resource_deadlock_would_occur, //EDEADLK
resource_unavailable_try_again, //EAGAIN
result_out_of_range, //ERANGE
state_not_recoverable, //ENOTRECOVERABLE
stream_timeout, //ETIME
text_file_busy, //ETXTBSY
timed_out, //ETIMEDOUT
too_many_files_open_in_system, //ENFILE
too_many_files_open, //EMFILE
too_many_links, //EMLINK
too_many_synbolic_link_levels, //ELOOP
value_too_large, //EOVERFLOW
wrong_protocol_type //EPROTOTYPE
};

} // namespace errc

template<> struct is_error_condition_enum<errc::errc_t>
{ static const bool value = true; };

bool operator==( const error_code & lhs, const error_code & rhs );
bool operator==( const error_code & code, const error_condition & condition );
bool operator==( const error_condition & condition, const error_code & code );
bool operator==( const error_condition & lhs, const error_condition & rhs );

bool operator!=( const error_code & lhs, const error_code & rhs );
bool operator!=( const error_code & code, const error_condition & condition );
bool operator!=( const error_condition & condition, const error_code & code );
bool operator!=( const error_condition & lhs, const error_condition & rhs );

bool operator<( const error_code & lhs, const error_code & rhs );
bool operator<( const error_condition & lhs, const error_condition & rhs );

error_code make_error_code( errc::errc_t e );
error_condition make_error_condition( errc::errc_t e );

template <class charT, class traits>
std::basic_ostream<charT,traits>&
operator<<( basic_ostream<charT,traits>& os, const error_code & ec );

size_t hash_value( const error_code & ec );
}
}

The value of each errc_t constant shall be the same as the value of the <cerrno> macro shown in the above synopsis.
每個 errc_t 常量的值應該與以上概要中的 <cerrno> 宏的值相同。

Users may specialize is_error_code_enum and is_error_condition_enum templates to indicate that a type is eligible for class error_code and error_condition automatic conversions respectively.
用戶可以特化 is_error_code_enum is_error_condition_enum 模板,以表示某種符合條件的類型,可以分別自動轉換為類 error_codeerror_condition.

Class error_category

The class error_category defines the base class for types used to identify the source and encoding of a particular category of error code.

error_category 定義了一個基類,用作標識某種特定的錯誤代碼類別的源和編碼的類型的基類。

[Note: Classes may be derived from error_category to support additional categories of errors. --end note]

[注: 可以從 error_category 派生出其它類,以支持其它錯誤類別。--注完]

The class error_category serves as a base class for types used to identify the source and encoding of a particular category of error code. Classes may be derived from error_category to support categories of errors in addition to those defined in the Boost System library. Such classes shall behave as specified in this subclause. [ Note: error_category objects are passed by reference, and two such objects are equal if they have the same address. This means that applications using custom error_category types should create a single object of each such type. —end note ]

類 error_category 被用作標識某種特定的錯誤代碼類別的源和編碼的類型的基類。可以從 error_category 派生出其它類,以支持除了已在 Boost System 庫中定義的錯誤類別之外錯誤。這些類應該遵守本條款中所規定的行為。[ 注: error_category 對象是按引用傳遞的,兩個同類對像如果具有相同地址,就是相等的。這意味著使用客戶化 error_category 類型的應用程序應該為每一種類型創建單一個對象。—注完]

Class error_category synopsis 概要

namespace boost
{
namespace system
{
class error_category : public noncopyable
{
public:
virtual ~error_category();

virtual const char * name() const = 0;
virtual string message( error_code::value_type ev ) const = 0;
virtual error_condition default_error_condition( int ev ) const;
virtual bool equivalent( int code, const error_condition & condition ) const;
virtual bool equivalent( const error_code & code, int condition ) const;

bool operator==( const error_category & rhs ) const;
bool operator!=( const error_category & rhs ) const;
bool operator< ( const error_category & rhs ) const;
};

const error_category & get_system_category();
const error_category & get_generic_category();

static const error_category & system_category = get_system_category();
static const error_category & generic_category = get_generic_category();
}
}

Class error_category virtual members 虛擬成員

Classes derived from error_category shall behave as specified in this subclause.

派生自 error_category 的類應該遵守本條款的行為。

virtual const char * name() const=0;

Returns: a string naming the error category.

返回: 錯誤類別的字符串名字。

Throws: Nothing.

拋出: 無。

virtual string message( error_code::value_type ev ) const=0;

Returns: A string that describes the error denoted by ev.

返回: 描述由 ev 表示的錯誤的字符串。

Throws: Nothing.

拋出: 無。

virtual error_condition default_error_condition( int ev ) const;

Returns:  error_condition( ev, *this ).

返回:  error_condition( ev, *this ).

[--Note: Derived classes will typically convert ev to some portable error_category, such as generic_category, and return it as an error_condition for that category. --end note]

[--注: 派生類通常會將 ev 轉換為某個可移植的 error_category, 如 generic_category, 並將它作為該類別的 error_condition 返回。--注完]

Throws: Nothing.

拋出: 無。

virtual bool equivalent( int code, const error_condition & condition ) const;

Returns: default_error_condition( code ) == condition.

返回: default_error_condition( code ) == condition.

Throws: Nothing.

拋出: 無。

virtual bool equivalent( const error_code & code, int condition ) const;

Returns: *this == code.category() && code.value() == condition.

返回: *this == code.category() && code.value() == condition.

Throws: Nothing.

拋出: 無。

Class error_category non-virtual members 非虛擬成員

bool operator==( const error_category & rhs ) const;

Returns: this == &rhs.

返回: this == &rhs.

bool operator!=( const error_category & rhs ) const;

Returns: this != &rhs.

返回: this != &rhs.

bool operator<( const error_category & rhs ) const;

Returns: std::less<const error_category*>()( this, &rhs ).

返回: std::less<const error_category*>()( this, &rhs ).

[Note: std::less provides a total ordering for pointers. --end note]
[注:
std::less 提供了對指針的全序關係。--注完]

Throws: Nothing.

拋出: 無。

Class error_category non-member functions 非成員函數

const error_category & get_system_category();

Returns: A reference to a error_category object identifying errors originating from the operating system.

返回: 某個 error_category 對象的引用,表示錯誤來自於操作系統。

Throws: Nothing.

拋出: 無。

const error_category & get_generic_category();

Returns: A reference to a error_category object identifying portable error conditions.

返回: 某個 error_category 對象的引用,表示可移植的錯誤條件。

Throws: Nothing.

拋出: 無。

Class error_category predefined objects 預定義對像

Predefined objects system_category and generic_category identify operating system error codes and portable error conditions, respectively.

預定義對像 system_category 和 generic_category 分別表示操作系統錯誤代碼和可移植錯誤條件。

Class error_code

The class error_code describes an object used to hold error code values, such as those originating from the operating system or other low-level application program interfaces. [ Note: Class error_code is an adjunct to error reporting by exception. —end note ]

error_code 描述了一個對象,它用於保存錯誤代碼值,這些錯誤代碼來自於操作系統或其它底層API。[ 注: error_code 是以異常方式報告錯誤的輔助手段。—注完 ]

Class error_code synopsis 概要

namespace boost
{
namespace system
{
class error_code {
public:

// constructors: 構造函數
error_code();
error_code( val, const error_category & cat );
template <class ErrorCodeEnum>
error_code( errorCodeEnum e,
typename enable_if<is_error_code_enum<ErrorCodeEnum> >::type* = 0);

// modifiers: 修改器
void assign( int val, const error_category & cat );
template<typename ErrorCodeEnum>
typename enable_if<is_error_code_enum<ErrorCodeEnum>, error_code>::type &
operator=( ErrorCodeEnum val );;
void clear();

// observers: 觀察器
int value() const;
cont error_category & category() const;
error_condition default_error_condition() const;
string message() const;
operator unspecified-bool-type() const;

private:
int val_; // exposition only 僅用於說明 const error_category & cat_; // exposition only 僅用於說明 }; } }

Class error_code constructors 構造函數

error_code();

Effects: Constructs an object of type error_code.

作用: 構造類型 error_code 的一個對象。

Postconditions: val_ == 0 && cat_ == &system_category.

後置條件: val_ == 0 && cat_ == &system_category.

Throws: Nothing.

拋出: 無。

error_code( int val, const error_category & cat );

Effects: Constructs an object of type error_code.

作用: 構造類型 error_code 的一個對象。

Postconditions: val_ == val && cat_ == &cat.

後置條件: val_ == val && cat_ == &cat.

Throws: Nothing.

拋出: 無。

template <class ErrorCodeEnum>
error_code( errorCodeEnum val,
typename enable_if<is_error_code_enum<ErrorCodeEnum> >::type* = 0);

Effects: Constructs an object of type error_code.

作用: 構造類型 error_code 的一個對象。

Postconditions: *this == make_error_code( val ).

後置條件: *this == make_error_code( val ).

Throws: Nothing.

拋出: 無。

Class error_code modifiers 修改器

void assign( int val, const error_category & cat );

Postconditions: val_ == val && cat_ == cat.

後置條件: val_ == val && cat_ == cat.

Throws: Nothing.

拋出: 無。

template<typename ErrorCodeEnum>
typename enable_if<is_error_code_enum<ErrorCodeEnum>, error_code>::type &
operator=( ErrorCodeEnum val );

Postconditions: *this == make_error_code( val ).

後置條件: *this == make_error_code( val ).

Throws: Nothing.

拋出: 無。

void clear();

postcondition: value() == 0 && category() == posix_category
後置條件: value() == 0 && category() == posix_category

Class error_code observers 觀察器

int value() const;

Returns: val_.

返回: val_.

Throws: Nothing.

拋出: 無。

error_category category() const;

Returns: cat_.

返回: cat_.

Throws: Nothing.

拋出: 無。

error_condition default_error_condition() const;

Returns:  category().default_error_condition( value()).

返回:  category().default_error_condition( value()).

Throws: Nothing.

拋出: 無。

string message() const;

Returns:  category().message( value()).

返回:  category().message( value()).

Throws: Nothing.

拋出: 無。

operator unspecified-bool-type() const;

Returns: if value() != value_type(), returns a value that will evaluate true in a boolean context; otherwise, returns a value that will evaluate false in a boolean context. The value type returned shall not be convertible to int.

返回: 如果 value() != value_type(), 則返回一個在布爾上下文中被求值為 true 的值,否則返回一個在布爾上下文中被求值為 false 的值。被返回的值類型不應可轉換為 int.

Throws: nothing.

拋出: 無。

[Note: This conversion can be used in contexts where a bool is expected ( e.g., an if condition ); however, implicit conversions ( e.g., to int) that can occur with bool are not allowed, eliminating some sources of user error. One possible implementation choice for this type is pointer-to-member. --end note ]

[注: 該轉換可用於需要一個 bool 值的上下文中(如一個 if 條件中); 但是,又不允許隱式轉換(如轉換為 int)發生在 bool 值上,以消除某些用戶錯誤源。該類型的一個可能的實現選擇是成員指針。--注完]

Class error_condition

The class error_condition describes an object used to hold values identifying error conditions. [ Note: error_condition values are portable abstractions, while error_code values are implementation specific. --end note ]

error_condition 描述一個對象,用於保存表示錯誤條件的值。[ 注: error_condition 值是可移植的抽像值,而 error_code 值則是實現指定的。--注完 ]

Class error_condition synopsis 概要

namespace boost
{
namespace system
{
class error_condition
{
public:

// constructors: 構造函數
error_condition();
error_condition( int val, const error_category & cat );
template <class ErrorConditionEnum>
error_condition( errorConditionEnum val,
typename enable_if<is_error_condition_enum<ErrorConditionEnum> >::type* = 0 );

// modifiers: 修改器
void assign( int val, const error_category & cat );
template<typename ErrorConditionEnum>
typename enable_if<is_error_condition_enum<ErrorConditionEnum>, error_code>::type &
operator=( ErrorConditionEnum val );
void clear();

// observers: 觀察器
int value() const;
const error_category & category() const;
string message() const;
operator unspecified-bool-type () const;

private:
int val_; // exposition only 僅用於說明 const error_category & cat_; // exposition only 僅用於說明 }; } }

Class error_condition constructors 構造函數

error_condition(); 

Effects: Constructs an object of type error_condition.

作用: 構造類型 error_condition 的一個對象。

Postconditions: val_ == 0 and cat_ == generic_category.

後置條件: val_ == 0 且 cat_ == generic_category.

Throws: Nothing.

拋出: 無。

error_condition( value_type val, const error_category & cat );

Effects: Constructs an object of type error_condition.

作用: 構造類型 error_condition 的一個對象。

Postconditions: val_ == val and cat_ == cat.

後置條件: val_ == val 且 cat_ == cat.

Throws: Nothing.

拋出: 無。

template <class ErrorConditionEnum>
error_condition( errorConditionEnum val,
typename enable_if<is_error_condition_enum<ErrorConditionEnum> >::type* = 0 );

Effects: Constructs an object of type error_condition.

作用: 構造類型 error_condition 的一個對象。

Postconditions: *this == make_error_condition( val ).

後置條件: *this == make_error_condition( val ).

Throws: Nothing.

拋出: 無。

Class error_condition modifiers 修改器

void assign( value_type val, const error_category & cat ); 

Postconditions: val_ == val and cat_ == cat.

後置條件: val_ == val 且 cat_ == cat.

Throws: Nothing.

拋出: 無。

template<typename ErrorConditionEnum>
typename enable_if<is_error_condition_enum<ErrorConditionEnum>, error_code>::type &
operator=( ErrorConditionEnum val );

Postconditions: *this == make_error_condition( val ).

後置條件: *this == make_error_condition( val ).

Throws: Nothing.

拋出: 無。

void clear();

postcondition: value() == 0 && category() == generic_category
後置條件: value() == 0 && category() == generic_category

Class error_condition observers 觀察器

value_type value() const;

Returns: val_.

返回: val_.

Throws: Nothing

拋出: 無。

const error_category & category() const;

Returns: cat_.

返回: cat_.

Throws: Nothing.

拋出: 無。

string message() const;

Returns: category().message( value() ).

返回: category().message( value() ).

Throws: Nothing.

拋出: 無。

operator unspecified-bool-type () const;

Returns: If value() != 0, returns a value that will evaluate true in a boolean context; otherwise, returns a value that will evaluate false. The return type shall not be convertible to int.

返回: 如果 value() != 0, 則返回一個在布爾上下文中被求值為 true 的值,否則返回一個在布爾上下文中被求值為 false 的值。返回的類型應不可轉換為 int.

Throws: Nothing.

拋出: 無。

 [ Note: This conversion can be used in contexts where a bool is expected ( e.g., an if condition ); however, implicit conversions ( e.g., to int) that can occur with bool are not allowed, eliminating some sources of user error. One possible implementation choice for this type is pointer to member. --end note ]

[注: 該轉換可用於需要一個 bool 值的上下文中(如一個 if 條件中); 但是,又不允許隱式轉換(如轉換為 int)發生在 bool 值上,以消除某些用戶錯誤源。該類型的一個可能的實現選擇是成員指針。--注完]

throws 對像

extern error_code throws;

The predefined error_code object throws is supplied for use as a "throw on error" tag.
預定義的 error_code 對像 throws 被提供作為一個"錯誤時拋出"的標籤使用。

throws 對象的語義

Functions that specify an argument in the form error_code& ec=throws, with appropriate namespace qualifiers, have the following error handling semantics:
error_code& ec=throws 形式指定一個參數並帶有適當的名字空間限定符的函數,具有以下錯誤處理語義:

Postconditions:
後驗條件:

If &ec != &throws and an error occurred:
如果 &ec != &throws 且發生了錯誤:

if &ec != &throws and an error did not occur, ec.clear().
如果 &ec != &throws 且沒有發生錯誤,則 ec.clear()

Throws:
拋出:

If an error occurs and &ec == &throws, throws an exception of type system_error or of a type derived from system_error. The exception's code() member function returns a reference to an error_code object with the behavior specified in Postconditions.
如果發生了錯誤且 &ec == &throws,則拋出一個類型為 system_error 或派生自 system_error 的異常。該異常的 code() 成員函數將返回一個 error_code 對象的引用,該對像具有在 後驗條件 中所說的行為。

Non-member functions 非成員函數

bool operator==( const error_code & lhs, const error_code & rhs );

Returns: lhs.category() == rhs.category() && lhs.value() == rhs.value().

返回: lhs.category() == rhs.category() && lhs.value() == rhs.value().

Throws: Nothing.

拋出: 無。

bool operator==( const error_code & code, const error_condition & condition );
bool operator==( const error_condition & condition, const error_code & code );

Returns: code.category().equivalent( code.value(), condition )
|| condition.category().equivalent( code, condition.value() )
.

返回: code.category().equivalent( code.value(), condition )
|| condition.category().equivalent( code, condition.value() )
.

Throws: Nothing.

拋出: 無。

bool operator==( const error_condition & lhs, const error_condition & rhs );

Returns: lhs.category() == rhs.category() && lhs.value() == rhs.value().

返回: lhs.category() == rhs.category() && lhs.value() == rhs.value().

Throws: Nothing.

拋出: 無。

bool operator!=( const error_code & lhs, const error_code & rhs );

Returns: !(lhs == rhs ).

返回: !(lhs == rhs ).

Throws: Nothing.

拋出: 無。

bool operator!=( const error_code & code, const error_condition & condition );
bool operator!=( const error_condition & condition, const error_code & code );

Returns: !( code ==  condition ).

返回: !( code ==  condition ).

Throws: Nothing.

拋出: 無。

bool operator!=( const error_condition & lhs, const error_condition & rhs );

Returns: !(lhs == rhs ).

返回: !(lhs == rhs ).

Throws: Nothing.

拋出: 無。

bool operator<( const error_code & lhs, const error_code & rhs );

Returns: lhs.category() < rhs.category()
  || (lhs.category() == rhs.category() && lhs.value() < rhs.value())
.

返回: lhs.category() < rhs.category()
  || (lhs.category() == rhs.category() && lhs.value() < rhs.value())
.

Throws: Nothing.

拋出: 無。

bool operator<( const error_condition & lhs, const error_condition & rhs );

Returns: lhs.category() < rhs.category()
  || (lhs.category() == rhs.category() && lhs.value() < rhs.value())
.

返回: lhs.category() < rhs.category()
  || (lhs.category() == rhs.category() && lhs.value() < rhs.value())
.

Throws: Nothing.

拋出: 無。

error_code make_error_code( errc::errc_t e );

Returns: error_code( e, generic_category).

返回: error_code( e, generic_category).

error_condition make_error_condition( errc::errc_t e );

Returns: error_condition( e, generic_category).

返回: error_condition( e, generic_category).

template <class charT, class traits>
std::basic_ostream<charT,traits>&
operator<<( basic_ostream<charT,traits>& os, const error_code & ec );

Effects: os << ec.category().name() << ':' << ec.value().

作用: os << ec.category().name() << ':' << ec.value().

Returns: os.

返回: os.

size_t hash_value( const error_code & ec );

Returns:  A hash value representing ec.

返回:  一個表示 ec 的散列值。

Header 頭文件 <boost/system/system_error.hpp>

Class system_error

The class system_error describes an exception object used to report error conditions that have an associated error code. Such error conditions typically originate from the operating system or other low-level application program interfaces.

類 system_error 描述了一個異常對象,用於報告具有關聯錯誤代碼的錯誤條件。這類錯誤條件通常來自於操作系統或其它底層API。

namespace boost
{
namespace system
{
class system_error : public std::runtime_error
{
public:
system_error( error_code ec );
system_error( error_code ec, const char * what_arg );
system_error( error_code ec, const std::string & what_arg );
system_error( error_code::value_type ev, const error_category & ecat,
const char * what_arg );
system_error( error_code::value_type ev, const error_category & ecat,
const std::string & what_arg );
system_error( error_code::value_type ev, const error_category & ecat);

const error_code & code() const throw();
const char * what() const throw();
};
}
}
system_error( error_code ec );

Effects: Constructs an object of class system_error.

作用: 構造一個 system_error 類的對象。

Postcondition: code() == ec
  && std::strcmp( this->runtime_error::what(), "" ) == 0

後置條件: code() == ec
  && std::strcmp( this->runtime_error::what(), "" ) == 0

system_error( error_code ec, const char * what_arg );

Effects: Constructs an object of class system_error.
作用: 構造一個 system_error 類的對象。

Postcondition: code() == ec
  && std::strcmp( this->runtime_error::what(), what_arg ) == 0

後置條件: code() == ec
  && std::strcmp( this->runtime_error::what(), what_arg ) == 0

system_error( error_code ec, const std::string & what_arg );

Effects: Constructs an object of class system_error.

作用: 構造一個 system_error 類的對象。

Postcondition: code() == ec
  && std::strcmp( this->runtime_error::what(), what_arg.c_str() ) == 0

後置條件: code() == ec
  && std::strcmp( this->runtime_error::what(), what_arg.c_str() ) == 0

system_error( error_code::value_type ev, const error_category & ecat,
const char * what_arg );

Effects: Constructs an object of class system_error.

作用: 構造一個 system_error 類的對象。

Postcondition: code() == error_code( ev, ecat )
  && std::strcmp( this->runtime_error::what(), what_arg ) == 0

後置條件: code() == error_code( ev, ecat )
  && std::strcmp( this->runtime_error::what(), what_arg ) == 0

system_error( error_code::value_type ev, const error_category & ecat,
const std::string & what_arg );

Effects: Constructs an object of class system_error.

作用: 構造一個 system_error 類的對象。

Postcondition: code() == error_code( ev, ecat )
  && std::strcmp( this->runtime_error::what(), what_arg.c_str() ) == 0

後置條件: code() == error_code( ev, ecat )
  && std::strcmp( this->runtime_error::what(), what_arg.c_str() ) == 0

system_error( error_code::value_type ev, const error_category & ecat );

Effects: Constructs an object of class system_error.

作用: 構造一個 system_error 類的對象。

Postcondition: code() == error_code( ev, ecat )
  && std::strcmp( this->runtime_error::what(), "" ) == 0

後置條件: code() == error_code( ev, ecat )
  && std::strcmp( this->runtime_error::what(), "" ) == 0

const error_code & code() const;

Returns: ec or error_code( ev, ecat ), from the constructor, as appropriate.

返回: ecerror_code( ev, ecat ), 來自於構造函數。

const char * what() const;

Returns: A string incorporating this->runtime_error::what() and code.message().

返回: 一個合併了 this->runtime_error::what() code.message() 的字符串。


Revised October 11, 2008

c Copyright Beman Dawes, 2006, 2007, 2008

Distributed under the Boost Software License, Version 1.0. See www.boost.org/LICENSE_1_0.txt