diff --git a/doc/BOOST_THROW_EXCEPTION.html b/doc/BOOST_THROW_EXCEPTION.html index 89395fb..7d8806f 100644 --- a/doc/BOOST_THROW_EXCEPTION.html +++ b/doc/BOOST_THROW_EXCEPTION.html @@ -27,15 +27,15 @@ #include <boost/current_function.hpp> #define BOOST_THROW_EXCEPTION(x)\ ::boost::throw_exception( ::boost::enable_error_info(x) <<\ - ::boost::throw_function(BOOST_CURRENT_FUNCTION) <<\ + ::boost::throw_function(BOOST_THROW_EXCEPTION_CURRENT_FUNCTION) <<\ ::boost::throw_file(__FILE__) <<\ ::boost::throw_line((int)__LINE__) ) #else #define BOOST_THROW_EXCEPTION(x) ::boost::throw_exception(x) #endif -

This macro takes an exception object, records BOOST_CURRENT_FUNCTION, __FILE__ and __LINE__ in it, and forwards it to throw_exception. To recover this information at the catch site, use get_error_info; the information is also included in the message returned by diagnostic_information.

+

This macro takes an exception object, records the current function name, __FILE__ and __LINE__ in it, and forwards it to throw_exception. To recover this information at the catch site, use get_error_info; the information is also included in the message returned by diagnostic_information.


-See also: Boost Exception | boost/throw_exception.hpp | Frequently Asked Questions +See also: Boost Exception | boost/throw_exception.hpp | Configuration Macros | Frequently Asked Questions
diff --git a/doc/boost_exception_all_hpp.html b/doc/boost_exception_all_hpp.html index d41a493..55db249 100644 --- a/doc/boost_exception_all_hpp.html +++ b/doc/boost_exception_all_hpp.html @@ -40,7 +40,7 @@ #include <boost/exception_ptr.hpp> #endif

-See also: boost/exception.hpp | Diagnostic Information | Integrating Boost Exception in Existing Exception Class Hierarchies | Synopsis +See also: Diagnostic Information | Integrating Boost Exception in Existing Exception Class Hierarchies | Synopsis
diff --git a/doc/boost_exception_diagnostic_information_hpp.html b/doc/boost_exception_diagnostic_information_hpp.html index d2e1bb1..a3a739a 100644 --- a/doc/boost_exception_diagnostic_information_hpp.html +++ b/doc/boost_exception_diagnostic_information_hpp.html @@ -30,11 +30,11 @@ boost class exception; template <class E> - std::string diagnostic_information( E const & e ); + std::string diagnostic_information( E const & e, bool verbose=true ); - std::string diagnostic_information( exception_ptr const & p ); + std::string diagnostic_information( exception_ptr const & p, bool verbose=true ); - char const * diagnostic_information_what( boost::exception const & e ) throw(); + char const * diagnostic_information_what( boost::exception const & e, bool verbose=true ) throw(); std::string current_exception_diagnostic_information(); } diff --git a/doc/boost_exception_get_error_info_hpp.html b/doc/boost_exception_get_error_info_hpp.html index 55fe7ca..1850ab8 100644 --- a/doc/boost_exception_get_error_info_hpp.html +++ b/doc/boost_exception_get_error_info_hpp.html @@ -28,10 +28,10 @@ namespace boost { template <class ErrorInfo,class E> - typename ErrorInfo::error_info::value_type const * get_error_info( E const & x ); + typename ErrorInfo::error_info::value_type const * get_error_info( E const & x ); template <class ErrorInfo,class E> - typename ErrorInfo::error_info::value_type * get_error_info( E & x ); + typename ErrorInfo::error_info::value_type * get_error_info( E & x ); }

See also: boost/exception/all.hpp | error_info diff --git a/doc/boost_exception_hpp.html b/doc/boost_exception_hpp.html deleted file mode 100644 index 821f567..0000000 --- a/doc/boost_exception_hpp.html +++ /dev/null @@ -1,42 +0,0 @@ - - - - - boost/exception.hpp - - - -
-
-
-
- -

Boost Exception

-
- - - -

boost/exception.hpp

-
-

This header has been deprecated.

-

Please #include <boost/exception/all.hpp> instead.

-
- - - - -
-
-
- - diff --git a/doc/boost_throw_exception_hpp.html b/doc/boost_throw_exception_hpp.html index 735ac77..a99cd9b 100644 --- a/doc/boost_throw_exception_hpp.html +++ b/doc/boost_throw_exception_hpp.html @@ -27,7 +27,7 @@ #include <boost/current_function.hpp> #define BOOST_THROW_EXCEPTION(x)\ ::boost::throw_exception( ::boost::enable_error_info(x) <<\ - ::boost::throw_function(BOOST_CURRENT_FUNCTION) <<\ + ::boost::throw_function(BOOST_THROW_EXCEPTION_CURRENT_FUNCTION) <<\ ::boost::throw_file(__FILE__) <<\ ::boost::throw_line((int)__LINE__) ) #else diff --git a/doc/configuration_macros.html b/doc/configuration_macros.html index aac5b65..b19ff9f 100644 --- a/doc/configuration_macros.html +++ b/doc/configuration_macros.html @@ -32,8 +32,10 @@

Note that on some non-conformant compilers, for example MSVC 7.0 and older, as well as BCC, BOOST_EXCEPTION_DISABLE is implicitly defined in boost/throw_exception.hpp.

BOOST_NO_EXCEPTIONS

This macro disables exception handling in Boost, forwarding all exceptions to a user-defined non-template version of boost::throw_exception. However, unless BOOST_EXCEPTION_DISABLE is also defined, users can still examine the exception object for any data added at the point of the throw, or use boost::diagnostic_information (of course under BOOST_NO_EXCEPTIONS, the user-defined boost::throw_exception is not allowed to return to the caller.)

+

BOOST_THROW_EXCEPTION_CURRENT_FUNCTION

+

The BOOST_THROW_EXCEPTION macro uses BOOST_THROW_EXCEPTION_CURRENT_FUNCTION to record the name of the current function in the exception object. Unless overridden by the user, BOOST_THROW_EXCEPTION_CURRENT_FUNCTION expands to BOOST_CURRENT_FUNCTION.


-See also: Boost Exception | boost/exception/all.hpp | get_error_info +See also: BOOST_THROW_EXCEPTION | Boost Exception | boost/exception/all.hpp | Frequently Asked Questions | get_error_info
diff --git a/doc/current_exception_diagnostic_information.html b/doc/current_exception_diagnostic_information.html index 512005a..25b6841 100644 --- a/doc/current_exception_diagnostic_information.html +++ b/doc/current_exception_diagnostic_information.html @@ -52,7 +52,7 @@ main() } }

-See also: Boost Exception | boost/exception/diagnostic_information.hpp | diagnostic_information +See also: Boost Exception | boost/exception/diagnostic_information.hpp | diagnostic_information | Frequently Asked Questions
diff --git a/doc/diagnostic_information.html b/doc/diagnostic_information.html index a909eb4..2805813 100644 --- a/doc/diagnostic_information.html +++ b/doc/diagnostic_information.html @@ -26,25 +26,21 @@ boost { template <class E> - std::string diagnostic_information( E const & e ); + std::string diagnostic_information( E const & e, bool verbose=true ); - std::string diagnostic_information( exception_ptr const & p ); + std::string diagnostic_information( exception_ptr const & p, bool verbose=true ); }

Returns:

-

A string value that contains varying amount of implementation-specific diagnostic information about the passed object:

-

The diagnostic_information_what function is intended to be called from a user-defined std::exception::what() override. This allows diagnostic information to be returned as the what() string.

Returns:

diff --git a/doc/enable_current_exception.html b/doc/enable_current_exception.html index e85d235..eb3951e 100644 --- a/doc/enable_current_exception.html +++ b/doc/enable_current_exception.html @@ -48,7 +48,7 @@ throw boost::enable_current_exception(my_exception

Note:

Instead of using the throw keyword directly, it is preferable to call boost::throw_exception. This is guaranteed to throw an exception that derives from boost::exception and supports the exception_ptr functionality.


-See also: Boost Exception | boost/exception/enable_current_exception.hpp | Configuration Macros | copy_exception | current_exception | Frequently Asked Questions | Transporting of Exceptions Between Threads | throw_exception +See also: Boost Exception | boost/exception/enable_current_exception.hpp | Configuration Macros | copy_exception | current_exception | Transporting of Exceptions Between Threads
diff --git a/doc/enable_error_info.html b/doc/enable_error_info.html index bc0ceaa..9a0a4ab 100644 --- a/doc/enable_error_info.html +++ b/doc/enable_error_info.html @@ -37,7 +37,7 @@ boost

Throws:

Nothing.


-See also: BOOST_THROW_EXCEPTION | Boost Exception | boost/exception/enable_error_info.hpp | Configuration Macros | Frequently Asked Questions | Integrating Boost Exception in Existing Exception Class Hierarchies | throw_exception +See also: BOOST_THROW_EXCEPTION | Boost Exception | boost/exception/enable_error_info.hpp | Configuration Macros | Frequently Asked Questions | Integrating Boost Exception in Existing Exception Class Hierarchies
diff --git a/doc/exception.html b/doc/exception.html index e1f0f31..6149821 100644 --- a/doc/exception.html +++ b/doc/exception.html @@ -40,7 +40,7 @@ boost

To retrieve data from a boost::exception object, use the get_error_info function template.


See Also:

-
Configuration Macros | current_exception | current_exception_diagnostic_information | Diagnostic Information | diagnostic_information | diagnostic_information_what | enable_current_exception | enable_error_info | error_info | exception_ptr | Frequently Asked Questions | get_error_info | Motivation | Transporting of Arbitrary Data to the Catch Site | Transporting of Exceptions Between Threads | tuple/operator<< | unknown_exception
+
Configuration Macros | current_exception | current_exception_diagnostic_information | Diagnostic Information | diagnostic_information | diagnostic_information_what | enable_current_exception | enable_error_info | error_info | exception_ptr | Frequently Asked Questions | get_error_info | Motivation | Transporting of Arbitrary Data to the Catch Site | Transporting of Exceptions Between Threads | throw_exception | tuple/operator<< | unknown_exception
diff --git a/doc/exception_ptr.html b/doc/exception_ptr.html index 5e18b2f..e5d6e58 100644 --- a/doc/exception_ptr.html +++ b/doc/exception_ptr.html @@ -40,7 +40,7 @@ boost

Nesting of exceptions:

An exception_ptr can be added as error_info to any boost::exception. This is a convenient way to nest exceptions. There is no limit on the depth of the nesting, however cyclic references result in undefined behavior.


-See also: Boost Exception | boost/exception/errinfo_nested_exception.hpp | boost/exception_ptr.hpp | copy_exception | current_exception | diagnostic_information | enable_current_exception | Frequently Asked Questions | original_exception_type | rethrow_exception | unknown_exception +See also: Boost Exception | boost/exception/errinfo_nested_exception.hpp | boost/exception_ptr.hpp | copy_exception | current_exception | diagnostic_information | enable_current_exception | original_exception_type | rethrow_exception | throw_exception | unknown_exception
diff --git a/doc/frequently_asked_questions.html b/doc/frequently_asked_questions.html index 68b216e..2499bb7 100644 --- a/doc/frequently_asked_questions.html +++ b/doc/frequently_asked_questions.html @@ -21,9 +21,35 @@

Frequently Asked Questions

+

What is the cost of calling boost::throw_exception?

+

The cost is that boost::exception is added as a base of the exception emitted by boost::throw_exception (unless the passed type already derives from boost::exception.)

+

Calling boost::throw_exception does not cause dynamic memory allocations.

+

What is the cost of BOOST_THROW_EXCEPTION?

+

In addition to calling boost::throw_exception, BOOST_THROW_EXCEPTION invokes __FILE__, __LINE__ and the BOOST_THROW_EXCEPTION_CURRENT_FUNCTION macros. The space required to store the information is already included in sizeof(boost::exception).

+

Calling BOOST_THROW_EXCEPTION does not cause dynamic memory allocations.

+

Should I use boost::throw_exception or BOOST_THROW_EXCEPTION or just throw?

+

The benefit of calling boost::throw_exception instead of using throw directly is that it ensures that the emitted exception derives from boost::exception and that it is compatible with boost::current_exception.

+

The BOOST_THROW_EXCEPTION macro also results in a call to boost::throw_exception, but in addition it records in the exception object the __FILE__ and __LINE__ of the throw, as well as the pretty name of the function that throws. This enables boost::diagnostic_information to compose a more useful, if not user-friendly message.

+

Typical use of boost::diagnostic_information is:

+
catch(...)
+    {
+    std::cerr <<
+        "Unexpected exception, diagnostic information follows:\n" <<
+        current_exception_diagnostic_information();
+    }
+

This is a possible message it may display -- the information in the first line is only available if BOOST_THROW_EXCEPTION was used to throw:

+
example_io.cpp(70): Throw in function class boost::shared_ptr<struct _iobuf> __cdecl my_fopen(const char *,const char *)
+Dynamic exception type: class boost::exception_detail::clone_impl<class fopen_error>
+std::exception::what: example_io error
+[struct boost::errinfo_api_function_ *] = fopen
+[struct boost::errinfo_errno_ *] = 2, "No such file or directory"
+[struct boost::errinfo_file_name_ *] = tmp1.txt
+[struct boost::errinfo_file_open_mode_ *] = rb
+

In some development environments, the first line in that message can be clicked to show the location of the throw in the debugger, so it's easy to set a break point and run again to see the unexpected throw in the context of its call stack.

Why doesn't boost::exception derive from std::exception?

-

Despite that virtual inheritance should be used in deriving from base exception types, many programmers fail to follow this principle when deriving from std::exception. If boost::exception derives from std::exception, using the enable_error_info function with such user-defined types would introduce dangerous ambiguity which would break all catch(std::exception &) statements.

-

Of course, boost::exception should not be used to replace std::exception as a base type in exception type hierarchies. Instead, it should be included as a virtual base, in addition to std::exception (which should also be derived virtually.)

+

Despite that virtual inheritance should be used in deriving from base exception types, quite often exception types (including the ones defined in the standard library) don't derive from std::exception virtually.

+

If boost::exception derives from std::exception, using the enable_error_info function with such user-defined types would introduce dangerous ambiguity which would break all catch(std::exception &) statements.

+

Of course, boost::exception should not be used to replace std::exception as a base type in exception type hierarchies. Instead, it should be included as a virtual base, in addition to std::exception (which should probably also be derived virtually.)

Why is boost::exception abstract?

To prevent exception-neutral contexts from erroneously erasing the type of the original exception when adding error_info to an active exception object:

catch( boost::exception & e )
@@ -37,55 +63,16 @@
     e << foo_info(foo);
     throw; //Okay, re-throwing the original exception object.
     }
-

What is the space overhead of the boost::exception base class?

-

The space overhead for the boost::exception data members is negligible in the context of exception handling. Throwing objects that derive from boost::exception does not by itself cause dynamic memory allocations.

-

Deriving from boost::exception enables any data to be added to exceptions, which usually does allocate memory. However, this memory is reclaimed when the exception has been handled, and since typically user code does not allocate memory during the unrolling of the stack, adding error info to exceptions should not cause memory fragmentation.

-

Should I use boost::throw_exception or BOOST_THROW_EXCEPTION or just throw?

-

The benefit of calling boost::throw_exception instead of using throw directly is that it ensures that the emitted exception derives from boost::exception and that it is compatible with boost::current_exception.

-

The BOOST_THROW_EXCEPTION macro also results in a call to boost::throw_exception, but in addition it records in the exception object the __FILE__ and __LINE__ of the throw, as well as the pretty name of the function that throws. This has virtually no overhead, yet enables boost::diagnostic_information to compose a more useful, if not user-friendly message.

-

Typical use of boost::diagnostic_information is:

-
catch( boost::exception & e )
-    {
-    std::cerr << "OMG!" << boost::diagnostic_information(e);
-    }
-catch( ... )
-    {
-    std::cerr << "OMG!!!";
-    }
-

This is a possible message it may display, the first line is only possible if BOOST_THROW_EXCEPTION is used:

-
example_io.cpp(70): Throw in function class boost::shared_ptr<struct _iobuf> __cdecl my_fopen(const char *,const char *)
-Dynamic exception type: class boost::exception_detail::clone_impl<class fopen_error>
-std::exception::what: example_io error
-[struct boost::errinfo_api_function_ *] = fopen
-[struct boost::errinfo_errno_ *] = 2, "No such file or directory"
-[struct boost::errinfo_file_name_ *] = tmp1.txt
-[struct boost::errinfo_file_open_mode_ *] = rb
-

Why is boost::exception integrated in boost::throw_exception?

-

The boost::throw_exception function predates the Boost Exception library and there has been some concern about its current behavior of injecting boost::exception as a base of any exception passed to boost::throw_exception. Such concerns are dictated by the typical strict interpretation of a common principle in C and C++, that users only pay for features they actually use.

-

The problem is that users of Boost Exception can't by themselves cause a library to throw types that derive from boost::exception, and without this they can't use any of the Boost Exception facilities.

-

For example, if a user wants to use Boost Serialization in a separate thread, it is desirable to be able to transport exceptions emitted by that library into the main thread where they can be analyzed to generate a user-friendly message. This can be easily achieved using boost::exception_ptr, but this requires that Boost Serialization throws exceptions using boost::enable_current_exception. If Boost Serialization calls boost::throw_exception to throw, this behavior happens automatically and transparently.

-

The cost of this integration is:

-

Why use operator<< overload for adding info to exceptions?

-

Before throwing an object of type that derives from boost::exception, it is often desirable to add one or more error_info objects in it. The syntactic sugar provided by exception/operator<< allows this to be done directly in a throw expression:

+

Before throwing an object of type that derives from boost::exception, it is often desirable to add one or more error_info objects in it. The syntactic sugar provided by operator<< allows this to be done directly in a throw expression:

throw error() << foo_info(foo) << bar_info(bar);
-

which saves typing compared to this possible alternative:

-
error e;
-e.add(foo_info(foo));
-e.add(bar_info(bar));
-throw e;
-

and looks better than something like:

-
throw error().add(foo_info(foo)).add(bar_info(bar));

Why is operator<< allowed to throw?

This question is referring to the following issue. Consider this throw statement example:

throw file_open_error() << file_name(fn);

The intention here is to throw a file_open_error, however if operator<< fails to copy the std::string contained in the file_name error_info wrapper, a std::bad_alloc could propagate instead. This behavior seems undesirable to some programmers.

Bjarne Stroustrup, The C++ Programming Language, 3rd Edition, page 371:

"Throwing an exception requires an object to throw. A C++ implementation is required to have enough spare memory to be able to throw bad_alloc in case of memory exhaustion. However, it is possible that throwing some other exception will cause memory exhaustion."

-

So, an attempt to throw any exception may already result in propagating std::bad_alloc instead.

+

Therefore, the language itself does not guarantee that an attempt to throw an exception is guaranteed to throw an object of the specified type; propagating a std::bad_alloc seems to be a possibility even outside of the scope of Boost Exception.


See also: Boost Exception | Motivation
diff --git a/doc/get_error_info.html b/doc/get_error_info.html index 90b5fcc..73c6770 100644 --- a/doc/get_error_info.html +++ b/doc/get_error_info.html @@ -25,10 +25,10 @@ boost { template <class ErrorInfo,class E> - typename ErrorInfo::error_info::value_type const * get_error_info( E const & x ); + typename ErrorInfo::error_info::value_type const * get_error_info( E const & x ); template <class ErrorInfo,class E> - typename ErrorInfo::error_info::value_type * get_error_info( E & x ); + typename ErrorInfo::error_info::value_type * get_error_info( E & x ); }

Requirements:


-See also: BOOST_THROW_EXCEPTION | Boost Exception | boost/exception/get_error_info.hpp | Configuration Macros | current_exception | error_info | exception | Motivation | throw_exception +See also: BOOST_THROW_EXCEPTION | Boost Exception | boost/exception/get_error_info.hpp | Configuration Macros | current_exception | error_info | exception | Motivation
diff --git a/doc/synopsis.html b/doc/synopsis.html index 1b071eb..95d12db 100644 --- a/doc/synopsis.html +++ b/doc/synopsis.html @@ -103,11 +103,11 @@ boost class exception; template <class E> - std::string diagnostic_information( E const & e ); + std::string diagnostic_information( E const & e, bool verbose=true ); - std::string diagnostic_information( exception_ptr const & p ); + std::string diagnostic_information( exception_ptr const & p, bool verbose=true ); - char const * diagnostic_information_what( boost::exception const & e ) throw(); + char const * diagnostic_information_what( boost::exception const & e, bool verbose=true ) throw(); std::string current_exception_diagnostic_information(); } @@ -158,7 +158,7 @@ boost #include <boost/current_function.hpp> #define BOOST_THROW_EXCEPTION(x)\ ::boost::throw_exception( ::boost::enable_error_info(x) <<\ - ::boost::throw_function(BOOST_CURRENT_FUNCTION) <<\ + ::boost::throw_function(BOOST_THROW_EXCEPTION_CURRENT_FUNCTION) <<\ ::boost::throw_file(__FILE__) <<\ ::boost::throw_line((int)__LINE__) ) #else diff --git a/doc/throw_exception.html b/doc/throw_exception.html index 4c24cda..eb03fdb 100644 --- a/doc/throw_exception.html +++ b/doc/throw_exception.html @@ -32,14 +32,17 @@ boost void throw_exception( E const & e ); #endif } -

Requirements:

-

E must derive publicly from std::exception.

-

Effects:

-

Effects:

+
-

Note:

-

Under BOOST_NO_EXCEPTIONS, unless BOOST_EXCEPTION_DISABLE is also defined, users can examine the passed exception object using boost::get_error_info, or format an automatic diagnostic message using boost::diagnostic_information.

+

Requirements:

+

E must derive publicly from std::exception. E may or may not derive from boost::exception.

+

Notes:

+

See also: BOOST_THROW_EXCEPTION | Boost Exception | boost/throw_exception.hpp | Configuration Macros | enable_current_exception | Frequently Asked Questions | Transporting of Exceptions Between Threads
diff --git a/include/boost/exception/all.hpp b/include/boost/exception/all.hpp index 9ffe42a..32eb150 100644 --- a/include/boost/exception/all.hpp +++ b/include/boost/exception/all.hpp @@ -5,7 +5,7 @@ #ifndef UUID_316FDA946C0D11DEA9CBAE5255D89593 #define UUID_316FDA946C0D11DEA9CBAE5255D89593 -#if defined(__GNUC__) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS) +#if (__GNUC__*100+__GNUC_MINOR__>301) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS) #pragma GCC system_header #endif #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS) diff --git a/include/boost/exception/current_exception_cast.hpp b/include/boost/exception/current_exception_cast.hpp index af2f153..5d81f00 100644 --- a/include/boost/exception/current_exception_cast.hpp +++ b/include/boost/exception/current_exception_cast.hpp @@ -5,7 +5,7 @@ #ifndef UUID_7E83C166200811DE885E826156D89593 #define UUID_7E83C166200811DE885E826156D89593 -#if defined(__GNUC__) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS) +#if (__GNUC__*100+__GNUC_MINOR__>301) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS) #pragma GCC system_header #endif #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS) diff --git a/include/boost/exception/detail/error_info_impl.hpp b/include/boost/exception/detail/error_info_impl.hpp index a8d1aa7..12e601b 100644 --- a/include/boost/exception/detail/error_info_impl.hpp +++ b/include/boost/exception/detail/error_info_impl.hpp @@ -5,7 +5,7 @@ #ifndef UUID_CE6983AC753411DDA764247956D89593 #define UUID_CE6983AC753411DDA764247956D89593 -#if defined(__GNUC__) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS) +#if (__GNUC__*100+__GNUC_MINOR__>301) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS) #pragma GCC system_header #endif #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS) @@ -25,8 +25,7 @@ boost { public: - virtual std::string tag_typeid_name() const = 0; - virtual std::string value_as_string() const = 0; + virtual std::string name_value_string() const = 0; protected: @@ -63,8 +62,7 @@ boost private: - std::string tag_typeid_name() const; - std::string value_as_string() const; + std::string name_value_string() const; value_type value_; }; diff --git a/include/boost/exception/detail/exception_ptr.hpp b/include/boost/exception/detail/exception_ptr.hpp index 5e5a267..b2ee365 100644 --- a/include/boost/exception/detail/exception_ptr.hpp +++ b/include/boost/exception/detail/exception_ptr.hpp @@ -5,7 +5,7 @@ #ifndef UUID_618474C2DE1511DEB74A388C56D89593 #define UUID_618474C2DE1511DEB74A388C56D89593 -#if defined(__GNUC__) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS) +#if (__GNUC__*100+__GNUC_MINOR__>301) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS) #pragma GCC system_header #endif #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS) @@ -467,7 +467,7 @@ boost inline std::string - diagnostic_information( exception_ptr const & p ) + diagnostic_information( exception_ptr const & p, bool verbose=true ) { if( p ) try @@ -477,7 +477,7 @@ boost catch( ... ) { - return current_exception_diagnostic_information(); + return current_exception_diagnostic_information(verbose); } return ""; } diff --git a/include/boost/exception/detail/is_output_streamable.hpp b/include/boost/exception/detail/is_output_streamable.hpp index 743313c..847f348 100644 --- a/include/boost/exception/detail/is_output_streamable.hpp +++ b/include/boost/exception/detail/is_output_streamable.hpp @@ -5,7 +5,7 @@ #ifndef UUID_898984B4076411DD973EDFA055D89593 #define UUID_898984B4076411DD973EDFA055D89593 -#if defined(__GNUC__) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS) +#if (__GNUC__*100+__GNUC_MINOR__>301) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS) #pragma GCC system_header #endif #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS) diff --git a/include/boost/exception/detail/object_hex_dump.hpp b/include/boost/exception/detail/object_hex_dump.hpp index ccf1bac..53c8bf6 100644 --- a/include/boost/exception/detail/object_hex_dump.hpp +++ b/include/boost/exception/detail/object_hex_dump.hpp @@ -5,7 +5,7 @@ #ifndef UUID_6F463AC838DF11DDA3E6909F56D89593 #define UUID_6F463AC838DF11DDA3E6909F56D89593 -#if defined(__GNUC__) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS) +#if (__GNUC__*100+__GNUC_MINOR__>301) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS) #pragma GCC system_header #endif #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS) diff --git a/include/boost/exception/detail/type_info.hpp b/include/boost/exception/detail/type_info.hpp index 92f8464..15fa1c4 100644 --- a/include/boost/exception/detail/type_info.hpp +++ b/include/boost/exception/detail/type_info.hpp @@ -5,7 +5,7 @@ #ifndef UUID_C3E1741C754311DDB2834CCA55D89593 #define UUID_C3E1741C754311DDB2834CCA55D89593 -#if defined(__GNUC__) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS) +#if (__GNUC__*100+__GNUC_MINOR__>301) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS) #pragma GCC system_header #endif #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS) diff --git a/include/boost/exception/diagnostic_information.hpp b/include/boost/exception/diagnostic_information.hpp index ef89d73..5ac8c6b 100644 --- a/include/boost/exception/diagnostic_information.hpp +++ b/include/boost/exception/diagnostic_information.hpp @@ -5,7 +5,7 @@ #ifndef UUID_0552D49838DD11DD90146B8956D89593 #define UUID_0552D49838DD11DD90146B8956D89593 -#if defined(__GNUC__) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS) +#if (__GNUC__*100+__GNUC_MINOR__>301) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS) #pragma GCC system_header #endif #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS) @@ -31,17 +31,17 @@ boost namespace exception_detail { - std::string diagnostic_information_impl( boost::exception const *, std::exception const *, bool ); + std::string diagnostic_information_impl( boost::exception const *, std::exception const *, bool, bool ); } inline std::string - current_exception_diagnostic_information() + current_exception_diagnostic_information( bool verbose=true) { boost::exception const * be=current_exception_cast(); std::exception const * se=current_exception_cast(); if( be || se ) - return exception_detail::diagnostic_information_impl(be,se,true); + return exception_detail::diagnostic_information_impl(be,se,true,verbose); else return "No diagnostic information available."; } @@ -107,7 +107,7 @@ boost inline std::string - diagnostic_information_impl( boost::exception const * be, std::exception const * se, bool with_what ) + diagnostic_information_impl( boost::exception const * be, std::exception const * se, bool with_what, bool verbose ) { if( !be && !se ) return "Unknown exception."; @@ -125,7 +125,7 @@ boost return wh; } std::ostringstream tmp; - if( be ) + if( be && verbose ) { char const * const * f=get_error_info(*be); int const * l=get_error_info(*be); @@ -149,36 +149,37 @@ boost } } #ifndef BOOST_NO_RTTI - tmp << std::string("Dynamic exception type: ") << - units::detail::demangle((be?(BOOST_EXCEPTION_DYNAMIC_TYPEID(*be)):(BOOST_EXCEPTION_DYNAMIC_TYPEID(*se))).type_->name()) << '\n'; + if ( verbose ) + tmp << std::string("Dynamic exception type: ") << + units::detail::demangle((be?(BOOST_EXCEPTION_DYNAMIC_TYPEID(*be)):(BOOST_EXCEPTION_DYNAMIC_TYPEID(*se))).type_->name()) << '\n'; #endif - if( with_what && se ) + if( with_what && se && verbose ) tmp << "std::exception::what: " << wh << '\n'; if( be ) if( char const * s=exception_detail::get_diagnostic_information(*be,tmp.str().c_str()) ) if( *s ) - return s; + return std::string(s); return tmp.str(); } } template std::string - diagnostic_information( T const & e ) + diagnostic_information( T const & e, bool verbose=true ) { - return exception_detail::diagnostic_information_impl(exception_detail::get_boost_exception(&e),exception_detail::get_std_exception(&e),true); + return exception_detail::diagnostic_information_impl(exception_detail::get_boost_exception(&e),exception_detail::get_std_exception(&e),true,verbose); } inline char const * - diagnostic_information_what( exception const & e ) throw() + diagnostic_information_what( exception const & e, bool verbose=true ) throw() { char const * w=0; #ifndef BOOST_NO_EXCEPTIONS try { #endif - (void) exception_detail::diagnostic_information_impl(&e,0,false); + (void) exception_detail::diagnostic_information_impl(&e,0,false,verbose); if( char const * di=exception_detail::get_diagnostic_information(e,0) ) return di; else diff --git a/include/boost/exception/errinfo_errno.hpp b/include/boost/exception/errinfo_errno.hpp index ea74010..2cf7cab 100644 --- a/include/boost/exception/errinfo_errno.hpp +++ b/include/boost/exception/errinfo_errno.hpp @@ -5,7 +5,7 @@ #ifndef UUID_F0EE17BE6C1211DE87FF459155D89593 #define UUID_F0EE17BE6C1211DE87FF459155D89593 -#if defined(__GNUC__) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS) +#if (__GNUC__*100+__GNUC_MINOR__>301) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS) #pragma GCC system_header #endif #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS) diff --git a/include/boost/exception/exception.hpp b/include/boost/exception/exception.hpp index 42d2787..31d4317 100644 --- a/include/boost/exception/exception.hpp +++ b/include/boost/exception/exception.hpp @@ -5,7 +5,7 @@ #ifndef UUID_274DA366004E11DCB1DDFE2E56D89593 #define UUID_274DA366004E11DCB1DDFE2E56D89593 -#if defined(__GNUC__) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS) +#if (__GNUC__*100+__GNUC_MINOR__>301) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS) #pragma GCC system_header #endif #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS) diff --git a/include/boost/exception/get_error_info.hpp b/include/boost/exception/get_error_info.hpp index 046f05a..96be763 100644 --- a/include/boost/exception/get_error_info.hpp +++ b/include/boost/exception/get_error_info.hpp @@ -5,7 +5,7 @@ #ifndef UUID_1A590226753311DD9E4CCF6156D89593 #define UUID_1A590226753311DD9E4CCF6156D89593 -#if defined(__GNUC__) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS) +#if (__GNUC__*100+__GNUC_MINOR__>301) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS) #pragma GCC system_header #endif #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS) diff --git a/include/boost/exception/info.hpp b/include/boost/exception/info.hpp index 7b56076..762a950 100644 --- a/include/boost/exception/info.hpp +++ b/include/boost/exception/info.hpp @@ -5,7 +5,7 @@ #ifndef UUID_8D22C4CA9CC811DCAA9133D256D89593 #define UUID_8D22C4CA9CC811DCAA9133D256D89593 -#if defined(__GNUC__) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS) +#if (__GNUC__*100+__GNUC_MINOR__>301) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS) #pragma GCC system_header #endif #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS) @@ -24,10 +24,18 @@ boost { template inline - typename enable_if,std::string>::type + std::string + error_info_name( error_info const & x ) + { + return tag_type_name(); + } + + template + inline + std::string to_string( error_info const & x ) { - return to_string(x.value()); + return '[' + error_info_name(x) + "] = " + to_string_stub(x.value()) + '\n'; } template @@ -49,16 +57,7 @@ boost inline std::string error_info:: - tag_typeid_name() const - { - return tag_type_name(); - } - - template - inline - std::string - error_info:: - value_as_string() const + name_value_string() const { return to_string_stub(*this); } @@ -114,7 +113,7 @@ boost for( error_info_map::const_iterator i=info_.begin(),end=info_.end(); i!=end; ++i ) { error_info_base const & x = *i->second; - tmp << '[' << x.tag_typeid_name() << "] = " << x.value_as_string() << '\n'; + tmp << x.name_value_string(); } tmp.str().swap(diagnostic_info_str_); } diff --git a/include/boost/exception/info_tuple.hpp b/include/boost/exception/info_tuple.hpp index bf1be15..70154fd 100644 --- a/include/boost/exception/info_tuple.hpp +++ b/include/boost/exception/info_tuple.hpp @@ -5,7 +5,7 @@ #ifndef UUID_63EE924290FB11DC87BB856555D89593 #define UUID_63EE924290FB11DC87BB856555D89593 -#if defined(__GNUC__) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS) +#if (__GNUC__*100+__GNUC_MINOR__>301) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS) #pragma GCC system_header #endif #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS) diff --git a/include/boost/exception/to_string.hpp b/include/boost/exception/to_string.hpp index 59bf83d..68541d2 100644 --- a/include/boost/exception/to_string.hpp +++ b/include/boost/exception/to_string.hpp @@ -5,7 +5,7 @@ #ifndef UUID_7E48761AD92811DC9011477D56D89593 #define UUID_7E48761AD92811DC9011477D56D89593 -#if defined(__GNUC__) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS) +#if (__GNUC__*100+__GNUC_MINOR__>301) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS) #pragma GCC system_header #endif #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS) @@ -19,11 +19,16 @@ namespace boost { + template + std::string to_string( std::pair const & ); + std::string to_string( std::exception const & ); + namespace to_string_detail { template typename disable_if,char>::type to_string( T const & ); + using boost::to_string; template struct has_to_string_impl; diff --git a/include/boost/exception/to_string_stub.hpp b/include/boost/exception/to_string_stub.hpp index e41d369..b6ab31c 100644 --- a/include/boost/exception/to_string_stub.hpp +++ b/include/boost/exception/to_string_stub.hpp @@ -5,7 +5,7 @@ #ifndef UUID_E788439ED9F011DCB181F25B55D89593 #define UUID_E788439ED9F011DCB181F25B55D89593 -#if defined(__GNUC__) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS) +#if (__GNUC__*100+__GNUC_MINOR__>301) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS) #pragma GCC system_header #endif #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS) @@ -101,6 +101,14 @@ boost { return exception_detail::to_string_dispatch::dispatch(x,s); } + + template + inline + std::string + to_string_stub( std::pair const & x, Stub s ) + { + return std::string("(") + to_string_stub(x.first,s) + ',' + to_string_stub(x.second,s) + ')'; + } } #if defined(_MSC_VER) && !defined(BOOST_EXCEPTION_ENABLE_WARNINGS) diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index a53b472..6195a70 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -28,7 +28,7 @@ run 2-throw_exception_no_exceptions_test.cpp ; run 3-throw_exception_no_integration_test.cpp ; run 4-throw_exception_no_both_test.cpp ; run cloning_test.cpp ; -run copy_exception_test.cpp /boost//thread : : : multi ; +run copy_exception_test.cpp ../../thread/src/tss_null.cpp /boost//thread : : : multi ; run unknown_exception_test.cpp ; run exception_test.cpp ; run enable_error_info_test.cpp helper1.cpp ; @@ -40,8 +40,8 @@ run refcount_ptr_test.cpp ; run current_exception_cast_test.cpp ; run no_exceptions_test.cpp : : : off ; run errinfos_test.cpp ; -run exception_ptr_test.cpp/BOOST_ENABLE_NON_INTRUSIVE_EXCEPTION_PTR /boost/exception /boost//thread : : : multi : non_intrusive_exception_ptr_test ; -run exception_ptr_test.cpp /boost//thread : : : multi ; +run exception_ptr_test.cpp/BOOST_ENABLE_NON_INTRUSIVE_EXCEPTION_PTR ../../thread/src/tss_null.cpp /boost/exception /boost//thread : : : multi : non_intrusive_exception_ptr_test ; +run exception_ptr_test.cpp ../../thread/src/tss_null.cpp /boost//thread : : : multi ; compile-fail exception_fail.cpp ; compile-fail throw_exception_fail.cpp ; diff --git a/test/diagnostic_information_test.cpp b/test/diagnostic_information_test.cpp index 85e8a67..05ec554 100644 --- a/test/diagnostic_information_test.cpp +++ b/test/diagnostic_information_test.cpp @@ -19,10 +19,7 @@ typedef boost::error_info tagged_int2; std::string to_string( tagged_int2 const & x ) { - if( x.value()==42 ) - return "fourty-two"; - else - return "bad value"; + return '[' +boost::error_info_name(x) + "] = " + (x.value()==42 ? "fourty-two" : "bad value"); } struct diff --git a/test/error_info_test.cpp b/test/error_info_test.cpp index 53a6d12..f3dda1a 100644 --- a/test/error_info_test.cpp +++ b/test/error_info_test.cpp @@ -249,12 +249,41 @@ test_catch_add_info() void test_add_tuple() { - typedef boost::tuple test_12; - typedef boost::tuple test_123; - typedef boost::tuple test_1235; + typedef boost::tuple<> tuple_test_; + typedef boost::tuple tuple_test_1; + typedef boost::tuple tuple_test_12; + typedef boost::tuple tuple_test_123; + typedef boost::tuple tuple_test_1235; try { - throw test_exception() << test_12(42,42u); + throw test_exception() << tuple_test_(); + } + catch( + test_exception & x ) + { + } + catch( + ... ) + { + BOOST_TEST(false); + } + try + { + throw test_exception() << tuple_test_1(42); + } + catch( + test_exception & x ) + { + BOOST_TEST( *boost::get_error_info(x)==42 ); + } + catch( + ... ) + { + BOOST_TEST(false); + } + try + { + throw test_exception() << tuple_test_12(42,42u); } catch( test_exception & x ) @@ -269,7 +298,7 @@ test_add_tuple() } try { - throw test_exception() << test_123(42,42u,42.0f); + throw test_exception() << tuple_test_123(42,42u,42.0f); } catch( test_exception & x ) @@ -285,7 +314,7 @@ test_add_tuple() } try { - throw test_exception() << test_1235(42,42u,42.0f,std::string("42")); + throw test_exception() << tuple_test_1235(42,42u,42.0f,std::string("42")); } catch( test_exception & x ) diff --git a/test/exception_ptr_test.cpp b/test/exception_ptr_test.cpp index 4f0eb0c..193fabc 100644 --- a/test/exception_ptr_test.cpp +++ b/test/exception_ptr_test.cpp @@ -44,7 +44,7 @@ thread_handle explicit thread_handle( boost::function const & f ): - t_(boost::bind(thread_wrapper,f,err_)) + t_(boost::bind(thread_wrapper,f,boost::ref(err_))) { } @@ -63,8 +63,8 @@ void join( thread_handle & t ) { t.t_.join(); - if( t.err_ ) - rethrow_exception(t.err_); + assert(t.err_); + rethrow_exception(t.err_); } boost::detail::atomic_count exc_count(0); @@ -79,7 +79,9 @@ exc: ++exc_count; } - exc( exc const & ) + exc( exc const & e ): + boost::exception(e), + std::exception(e) { ++exc_count; } @@ -109,6 +111,7 @@ check( boost::shared_ptr const & t ) try { join(*t); + BOOST_TEST(false); } catch( exc & e ) @@ -125,7 +128,7 @@ main() try { std::vector< boost::shared_ptr > threads; - std::generate_n(std::inserter(threads,threads.end()),256,boost::bind(create_thread,thread_func)); + std::generate_n(std::inserter(threads,threads.end()),1,boost::bind(create_thread,thread_func)); std::for_each(threads.begin(),threads.end(),check); return boost::report_errors(); }