diff --git a/doc/reference.html b/doc/reference.html index be513cd..a451c82 100644 --- a/doc/reference.html +++ b/doc/reference.html @@ -39,6 +39,7 @@ Introduction
Macros
+ Deprecated names
Header <boost/system/error_code.hpp>
Class error_category
   Class error_category synopsis
@@ -57,6 +58,8 @@    Class error_condition constructors
   Class error_condition modifiers
   Class error_condition observers
+ throws object
+ Semantics of throws object
Non-member functions
Header <boost/system/system_error.hpp>
   Class system_error
@@ -114,6 +117,45 @@ provided, so users may ignore these macros if they prefer.

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.

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Old name, now deprecatedNew name
namespace posixnamespace errc
namespace posix_errornamespace errc
enum posix_errnoenum errc_t
get_posix_category()get_generic_category()
posix_categorygeneric_category
errno_ecatgeneric_category
native_ecatsystem_category

Header <boost/system/error_code.hpp>

<boost/system/error_code.hpp> synopsis

@@ -223,6 +265,11 @@ provided, so users may ignore these macros if they prefer.

template<> struct is_error_condition_enum<errc::errc_t> { static const bool value = true; }; + // predefined error_code object used as "throw on error" tag + extern error_code throws; + + // non-member functions + 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 ); @@ -279,7 +326,7 @@ types should create a single object of each such type. virtual ~error_category(); virtual const char * name() const = 0; - virtual string message( error_code::value_type ev ) const = 0; + virtual string message( int 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; @@ -305,7 +352,7 @@ this subclause.

Returns: a string naming the error category.

Throws: Nothing.

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

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

@@ -370,7 +417,7 @@ non-member functions

Class error_category predefined objects

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

+and generic_category identify system specific error codes and portable error conditions, respectively.

Class error_code

The class error_code describes an object used to hold error code @@ -392,7 +439,7 @@ error_code synopsis error_code(); error_code( val, const error_category & cat ); template <class ErrorCodeEnum> - error_code( errorCodeEnum e, + error_code( ErrorCodeEnum e, typename enable_if<is_error_code_enum<ErrorCodeEnum> >::type* = 0); // modifiers: @@ -411,7 +458,7 @@ error_code synopsis private: int val_; // exposition only - const error_category & cat_; // exposition only + const error_category * cat_; // exposition only }; } } @@ -442,7 +489,7 @@ error_code constructors error_code modifiers

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

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

+

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

Throws: Nothing.

template<typename ErrorCodeEnum>
@@ -463,9 +510,9 @@ error_code observers
 

Returns: val_.

Throws: Nothing.

-

error_category category() const;

+

const error_category & category() const;

-

Returns: cat_.

+

Returns: *cat_.

Throws: Nothing.

error_condition default_error_condition() const;
@@ -480,7 +527,7 @@ error_code observers

operator unspecified-bool-type() const;

-

Returns: if value() != value_type(), returns a value that will evaluate +

Returns: if value() != 0, 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.

@@ -527,8 +574,8 @@ implementation specific. --end note ]

operator unspecified-bool-type () const; private: - int val_; // exposition only - const error_category & cat_; // exposition only + int val_; // exposition only + const error_category * cat_; // exposition only }; } } @@ -538,13 +585,13 @@ constructors
error_condition(); 

Effects: Constructs an object of type error_condition.

-

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

+

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

Throws: Nothing.

-
error_condition( value_type val, const error_category & cat );
+
error_condition( int val, const error_category & cat );

Effects: Constructs an object of type error_condition.

-

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

+

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

Throws: Nothing.

template <class ErrorConditionEnum>
@@ -557,9 +604,9 @@ constructors
 

Class error_condition modifiers

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

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

+

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

Throws: Nothing.

template<typename ErrorConditionEnum>
@@ -575,14 +622,14 @@ modifiers
 
 

Class error_condition observers

-
value_type value() const;
+
int value() const;

Returns: val_.

Throws: Nothing

const error_category & category() const;
-

Returns: cat_.

+

Returns: *cat_.

Throws: Nothing.

string message() const;
@@ -603,7 +650,37 @@ observers eliminating some sources of user error. One possible implementation choice for this type is pointer to member. --end note ]

-

Non-member functions

+

throws object

+
extern error_code throws;
+

The predefined error_code object throws is supplied +for use as a "throw on error" tag.

+

Semantics of throws object

+

Functions that specify an argument in the form error_code& ec=throws, +with appropriate namespace qualifiers, have the following error handling +semantics:

+
+

Postconditions:

+
+

If &ec != &throws and an error occurred:

+
    +
  • ec.value() returns the implementation specific error + number for the particular error that occurred.
  • +
  • ec.category() returns the + error_category for ec.value().
  • +
+

if &ec != &throws and an error did not occur, 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.

+
+
+

Non-member functions

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

Returns: lhs.category() == rhs.category() && lhs.value() == @@ -657,7 +734,7 @@ bool operator!=( const error_condition & condition, const error_code & c

error_condition make_error_condition( errc::errc_t e );
-

Returns: error_condition( e, generic_category).

+

Returns: error_condition( static_cast<int>( e ), generic_category).

template <class charT, class traits>
@@ -677,8 +754,7 @@ bool operator!=( const error_condition & condition, const error_code & c
 

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 +report errors that have an associated error_code. Such errors typically originate from operating system or other low-level application program interfaces.

namespace boost
@@ -691,11 +767,11 @@ application program interfaces.

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, + system_error( int ev, const error_category & ecat, const char * what_arg ); - system_error( error_code::value_type ev, const error_category & ecat, + system_error( int ev, const error_category & ecat, const std::string & what_arg ); - system_error( error_code::value_type ev, const error_category & ecat); + system_error( int ev, const error_category & ecat); const error_code & code() const throw(); const char * what() const throw(); @@ -721,21 +797,21 @@ application program interfaces.

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

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

Effects: Constructs an object of class system_error.

Postcondition: 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,
+
system_error( int ev, const error_category & ecat,
              const std::string & what_arg );

Effects: Constructs an object of class system_error.

Postcondition: 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 );
+
system_error( int ev, const error_category & ecat );

Effects: Constructs an object of class system_error.

Postcondition: code() == error_code( ev, ecat )
@@ -754,14 +830,15 @@ application program interfaces.


-

© Copyright Beman Dawes, 2006, 2007
-Distributed under the Boost Software License, Version 1.0. See -www.boost.org/LICENSE_1_0.txt

-

Revised -June 25, 2008 +October 11, 2008

+

© Copyright Beman Dawes, 2006, 2007, 2008

+ +

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

+ \ No newline at end of file diff --git a/include/boost/system/error_code.hpp b/include/boost/system/error_code.hpp index a5db008..c79c26c 100644 --- a/include/boost/system/error_code.hpp +++ b/include/boost/system/error_code.hpp @@ -224,9 +224,9 @@ namespace boost error_condition() : m_val(0), m_cat(&get_generic_category()) {} error_condition( int val, const error_category & cat ) : m_val(val), m_cat(&cat) {} - template - error_condition(ConditionEnum e, - typename boost::enable_if >::type* = 0) + template + error_condition(ErrorConditionEnum e, + typename boost::enable_if >::type* = 0) { *this = make_error_condition(e); } @@ -239,9 +239,9 @@ namespace boost m_cat = &cat; } - template - typename boost::enable_if, error_condition>::type & - operator=( ConditionEnum val ) + template + typename boost::enable_if, error_condition>::type & + operator=( ErrorConditionEnum val ) { *this = make_error_condition(val); return *this; @@ -311,9 +311,9 @@ namespace boost error_code() : m_val(0), m_cat(&get_system_category()) {} error_code( int val, const error_category & cat ) : m_val(val), m_cat(&cat) {} - template - error_code(CodeEnum e, - typename boost::enable_if >::type* = 0) + template + error_code(ErrorCodeEnum e, + typename boost::enable_if >::type* = 0) { *this = make_error_code(e); } @@ -325,9 +325,9 @@ namespace boost m_cat = &cat; } - template - typename boost::enable_if, error_code>::type & - operator=( CodeEnum val ) + template + typename boost::enable_if, error_code>::type & + operator=( ErrorCodeEnum val ) { *this = make_error_code(val); return *this; @@ -382,6 +382,9 @@ namespace boost }; + // predefined error_code object used as "throw on error" tag + BOOST_SYSTEM_DECL extern error_code throws; + // non-member functions ------------------------------------------------// inline bool operator!=( const error_code & lhs, diff --git a/src/error_code.cpp b/src/error_code.cpp index f2623fc..55fcfc6 100644 --- a/src/error_code.cpp +++ b/src/error_code.cpp @@ -61,11 +61,12 @@ namespace const char * generic_error_category::name() const { - return "GENERIC"; + return "generic"; } std::string generic_error_category::message( int ev ) const { + static std::string unknown_err( "Unknown error" ); // strerror_r is preferred because it is always thread safe, // however, we fallback to strerror in certain cases because: // -- Windows doesn't provide strerror_r. @@ -81,15 +82,19 @@ namespace || (defined(__osf__) && !defined(_REENTRANT))\ || (defined(__vms)) const char * c_str = std::strerror( ev ); - return std::string( c_str ? c_str : "Unknown error" ); - # else + return c_str + ? std::string( c_str ) + : unknown_err; + # else // use strerror_r char buf[64]; char * bp = buf; std::size_t sz = sizeof(buf); # if defined(__CYGWIN__) || defined(__USE_GNU) // Oddball version of strerror_r const char * c_str = strerror_r( ev, bp, sz ); - return std::string( c_str ? c_str : "Unknown error" ); + return c_str + ? std::string( c_str ) + : unknown_err; # else // POSIX version of strerror_r int result; @@ -100,7 +105,9 @@ namespace # if defined (__sgi) const char * c_str = strerror( ev ); result = 0; - return std::string( c_str ? c_str : "Unknown error" ); + return c_str + ? std::string( c_str ) + : unknown_err; # else result = strerror_r( ev, bp, sz ); # endif @@ -113,26 +120,31 @@ namespace result = errno; # endif if ( result != ERANGE ) break; - if ( sz > sizeof(buf) ) std::free( bp ); - sz *= 2; - if ( (bp = static_cast(std::malloc( sz ))) == 0 ) - return std::string( "ENOMEM" ); + if ( sz > sizeof(buf) ) std::free( bp ); + sz *= 2; + if ( (bp = static_cast(std::malloc( sz ))) == 0 ) + return std::string( "ENOMEM" ); } } + std::string msg; try { - std::string msg( ( result == invalid_argument ) ? "Unknown error" : bp ); - if ( sz > sizeof(buf) ) std::free( bp ); - sz = 0; - return msg; + msg = ( ( result == invalid_argument ) ? "Unknown error" : bp ); } + +# ifndef BOOST_NO_EXCEPTIONS + // See ticket #2098 catch(...) { - if ( sz > sizeof(buf) ) std::free( bp ); - throw; + // just eat the exception } - # endif - # endif +# endif + + if ( sz > sizeof(buf) ) std::free( bp ); + sz = 0; + return msg; + # endif // else POSIX version of strerror_r + # endif // else use strerror_r } // system_error_category implementation --------------------------------// @@ -154,7 +166,9 @@ namespace case EADDRNOTAVAIL: return make_error_condition( address_not_available ); case EAFNOSUPPORT: return make_error_condition( address_family_not_supported ); case EAGAIN: return make_error_condition( resource_unavailable_try_again ); +# if EALREADY != EBUSY // EALREADY and EBUSY are the same on QNX Neutrino case EALREADY: return make_error_condition( connection_already_in_progress ); +# endif case EBADF: return make_error_condition( bad_file_descriptor ); case EBADMSG: return make_error_condition( bad_message ); case EBUSY: return make_error_condition( device_or_resource_busy ); @@ -396,6 +410,12 @@ namespace boost namespace system { + BOOST_SYSTEM_DECL error_code throws; // "throw on error" special error_code; + // note that it doesn't matter if this + // isn't initialized before use since + // the only use is to take its + // address for comparison purposes + BOOST_SYSTEM_DECL const error_category & get_system_category() { static const system_error_category system_category_const; diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 3dc7468..7b14c76 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -10,7 +10,6 @@ project : requirements /boost/system//boost_system - BOOST_ALL_NO_LIB msvc:on ; diff --git a/test/msvc_system/common.vsprops b/test/msvc_system/common.vsprops new file mode 100644 index 0000000..9a558f8 --- /dev/null +++ b/test/msvc_system/common.vsprops @@ -0,0 +1,18 @@ + + + + + diff --git a/test/msvc_system/error_code_test/error_code_test.vcproj b/test/msvc_system/error_code_test/error_code_test.vcproj new file mode 100644 index 0000000..5857539 --- /dev/null +++ b/test/msvc_system/error_code_test/error_code_test.vcproj @@ -0,0 +1,199 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/msvc_system/msvc_system.sln b/test/msvc_system/msvc_system.sln new file mode 100644 index 0000000..71b8a8e --- /dev/null +++ b/test/msvc_system/msvc_system.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 10.00 +# Visual C++ Express 2008 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "error_code_test", "error_code_test\error_code_test.vcproj", "{81960557-E9A9-4E81-AC96-9E11C33CB058}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {81960557-E9A9-4E81-AC96-9E11C33CB058}.Debug|Win32.ActiveCfg = Debug|Win32 + {81960557-E9A9-4E81-AC96-9E11C33CB058}.Debug|Win32.Build.0 = Debug|Win32 + {81960557-E9A9-4E81-AC96-9E11C33CB058}.Release|Win32.ActiveCfg = Release|Win32 + {81960557-E9A9-4E81-AC96-9E11C33CB058}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal