diff --git a/doc/frequently_asked_questions.html b/doc/frequently_asked_questions.html index 69eeafe..3f3c988 100644 --- a/doc/frequently_asked_questions.html +++ b/doc/frequently_asked_questions.html @@ -79,6 +79,13 @@ 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.


See Also:

Boost Exception
diff --git a/doc/source/boost-exception.reno b/doc/source/boost-exception.reno index 44ec9e0..84bf5f3 100644 --- a/doc/source/boost-exception.reno +++ b/doc/source/boost-exception.reno @@ -5561,7 +5561,7 @@ - 65 + 71 2 (:auto !!:) !!!Why doesn't boost::exception derive from std::exception? Despite that (:link 1 @@ -5851,7 +5851,34 @@ 2 - |<<:) 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));@] + |<<:) 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() (:link + 1 + + 0 + + -52 + + + 2 + |<<:) file_name(fn);@] The intention here is to throw a file_open_error, however if (:link + 1 + + 0 + + -52 + + + 2 + mod="/":) fails to copy the std::string contained in the file_name + 1 + + 0 + + -18 + + + 2 + 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.