forked from boostorg/throw_exception
Update documentation
This commit is contained in:
@ -44,3 +44,7 @@ enable `boost::exception_ptr` support.
|
|||||||
The source location of the exception thrown by `boost::throw_with_location`
|
The source location of the exception thrown by `boost::throw_with_location`
|
||||||
can be retrieved, after `catch(std::exception const & x)`, by using
|
can be retrieved, after `catch(std::exception const & x)`, by using
|
||||||
`boost::get_throw_location(x)`.
|
`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.
|
||||||
|
@ -59,7 +59,7 @@ logical throw point, instead of always pointing into the helper.
|
|||||||
----
|
----
|
||||||
#include <boost/throw_exception.hpp>
|
#include <boost/throw_exception.hpp>
|
||||||
#include <boost/lexical_cast.hpp>
|
#include <boost/lexical_cast.hpp>
|
||||||
#include <boost/exception/diagnostic_information.hpp>
|
#include <boost/core/verbose_terminate_handler.hpp>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -93,24 +93,21 @@ void f2( std::size_t i, std::size_t n )
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
try
|
std::set_terminate( boost::core::verbose_terminate_handler );
|
||||||
{
|
|
||||||
f1( 0, 3 );
|
f1( 0, 3 );
|
||||||
f2( 4, 3 );
|
f2( 4, 3 );
|
||||||
}
|
|
||||||
catch( std::exception const & x )
|
|
||||||
{
|
|
||||||
std::cerr << boost::diagnostic_information( x ) << std::endl;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
----
|
----
|
||||||
|
|
||||||
Sample output:
|
Sample output:
|
||||||
|
|
||||||
```none
|
```none
|
||||||
example.cpp(31): Throw in function void f2(std::size_t, std::size_t)
|
std::terminate called after throwing an exception:
|
||||||
Dynamic exception type: boost::wrapexcept<std::out_of_range>
|
|
||||||
std::exception::what: Index out of range: 4 >= 3
|
type: boost::wrapexcept<std::out_of_range>
|
||||||
|
what(): Index out of range: 4 >= 3
|
||||||
|
location: <source>:31:34 in function 'f2'
|
||||||
```
|
```
|
||||||
|
|
||||||
## Using boost::throw_with_location
|
## Using boost::throw_with_location
|
||||||
|
@ -130,7 +130,8 @@ template<class E> boost::source_location get_throw_location( E const & e );
|
|||||||
```
|
```
|
||||||
|
|
||||||
Requires: :: `E` must be polymorphic.
|
Requires: :: `E` must be polymorphic.
|
||||||
Effects: :: If `e` is a subobject of the object thrown by
|
Effects: ::
|
||||||
`boost::throw_with_location( x, loc )`, returns `loc`. Otherwise, returns
|
* If `e` is a subobject of the object thrown by `boost::throw_with_location( x, loc )`, returns `loc`.
|
||||||
a default constructed source location.
|
* If `dynamic_cast<boost::exception const*>( e )` returns a nonzero value, returns the source location stored in that `boost::exception` subobject, if any.
|
||||||
|
* Otherwise, returns a default constructed source location.
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user