1// Copyright 2022 Peter Dimov
2// Distributed under the Boost Software License, Version 1.0.
3// https://www.boost.org/LICENSE_1_0.txt
4
5#include <boost/throw_exception.hpp>
6#include <boost/core/lightweight_test.hpp>
7
8#if defined(_MSC_VER)
9# pragma warning(disable: 4702) // unreachable code
10#endif
11
12class my_exception: public std::exception
13{
14};
15
16int main()
17{
18 boost::source_location location = BOOST_CURRENT_LOCATION;
19
20 try
21 {
22 boost::throw_exception( e: my_exception(), loc: location );
23
24 BOOST_ERROR( "boost::throw_exception failed to throw" );
25 }
26 catch( std::exception const & x )
27 {
28 boost::source_location loc = boost::get_throw_location( e: x );
29
30 BOOST_TEST_CSTR_EQ( loc.file_name(), location.file_name() );
31 BOOST_TEST_CSTR_EQ( loc.function_name(), location.function_name() );
32 BOOST_TEST_EQ( loc.line(), location.line() );
33 BOOST_TEST_EQ( loc.column(), location.column() );
34 }
35 catch( ... )
36 {
37 BOOST_ERROR( "boost::throw_exception failed to throw std::exception" );
38 }
39
40 return boost::report_errors();
41}
42

source code of boost/libs/throw_exception/test/throw_with_location_test4.cpp