diff --git a/doc/description.adoc b/doc/description.adoc index 0d1e868..10b6e87 100644 --- a/doc/description.adoc +++ b/doc/description.adoc @@ -44,3 +44,7 @@ enable `boost::exception_ptr` support. The source location of the exception thrown by `boost::throw_with_location` can be retrieved, after `catch(std::exception const & x)`, by using `boost::get_throw_location(x)`. + +`boost::get_throw_location` also works for exceptions thrown by the two argument +overload of `boost::throw_exception`, or by `BOOST_THROW_EXCEPTION`; in this case +it returns the source location stored in the `boost::exception` base class. diff --git a/doc/examples.adoc b/doc/examples.adoc index aa4f52c..bdfbb1d 100644 --- a/doc/examples.adoc +++ b/doc/examples.adoc @@ -59,7 +59,7 @@ logical throw point, instead of always pointing into the helper. ---- #include #include -#include +#include #include #include #include @@ -93,24 +93,21 @@ void f2( std::size_t i, std::size_t n ) int main() { - try - { - f1( 0, 3 ); - f2( 4, 3 ); - } - catch( std::exception const & x ) - { - std::cerr << boost::diagnostic_information( x ) << std::endl; - } + std::set_terminate( boost::core::verbose_terminate_handler ); + + f1( 0, 3 ); + f2( 4, 3 ); } ---- Sample output: ```none -example.cpp(31): Throw in function void f2(std::size_t, std::size_t) -Dynamic exception type: boost::wrapexcept -std::exception::what: Index out of range: 4 >= 3 +std::terminate called after throwing an exception: + + type: boost::wrapexcept + what(): Index out of range: 4 >= 3 + location: :31:34 in function 'f2' ``` ## Using boost::throw_with_location diff --git a/doc/reference.adoc b/doc/reference.adoc index 848fe5c..c624c96 100644 --- a/doc/reference.adoc +++ b/doc/reference.adoc @@ -130,7 +130,8 @@ template boost::source_location get_throw_location( E const & e ); ``` Requires: :: `E` must be polymorphic. -Effects: :: If `e` is a subobject of the object thrown by - `boost::throw_with_location( x, loc )`, returns `loc`. Otherwise, returns - a default constructed source location. +Effects: :: +* If `e` is a subobject of the object thrown by `boost::throw_with_location( x, loc )`, returns `loc`. +* If `dynamic_cast( e )` returns a nonzero value, returns the source location stored in that `boost::exception` subobject, if any. +* Otherwise, returns a default constructed source location.