mirror of
https://github.com/boostorg/throw_exception.git
synced 2025-07-14 21:16:31 +02:00
Define boost::wrapexcept when BOOST_NO_EXCEPTIONS is defined, to enable boost::make_exception_ptr
This commit is contained in:
@ -20,6 +20,7 @@
|
|||||||
// http://www.boost.org/libs/throw_exception
|
// http://www.boost.org/libs/throw_exception
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#include <boost/exception/exception.hpp>
|
||||||
#include <boost/assert/source_location.hpp>
|
#include <boost/assert/source_location.hpp>
|
||||||
#include <boost/config.hpp>
|
#include <boost/config.hpp>
|
||||||
#include <boost/config/workaround.hpp>
|
#include <boost/config/workaround.hpp>
|
||||||
@ -32,29 +33,12 @@
|
|||||||
namespace boost
|
namespace boost
|
||||||
{
|
{
|
||||||
|
|
||||||
// All boost exceptions are required to derive from std::exception,
|
|
||||||
// to ensure compatibility with BOOST_NO_EXCEPTIONS.
|
|
||||||
|
|
||||||
inline void throw_exception_assert_compatibility( std::exception const & ) {}
|
|
||||||
|
|
||||||
} // namespace boost
|
|
||||||
|
|
||||||
#if defined( BOOST_NO_EXCEPTIONS )
|
#if defined( BOOST_NO_EXCEPTIONS )
|
||||||
|
|
||||||
namespace boost
|
|
||||||
{
|
|
||||||
|
|
||||||
BOOST_NORETURN void throw_exception( std::exception const & e ); // user defined
|
BOOST_NORETURN void throw_exception( std::exception const & e ); // user defined
|
||||||
BOOST_NORETURN void throw_exception( std::exception const & e, boost::source_location const & loc ); // user defined
|
BOOST_NORETURN void throw_exception( std::exception const & e, boost::source_location const & loc ); // user defined
|
||||||
|
|
||||||
} // namespace boost
|
#endif
|
||||||
|
|
||||||
#else // !defined( BOOST_NO_EXCEPTIONS )
|
|
||||||
|
|
||||||
#include <boost/exception/exception.hpp>
|
|
||||||
|
|
||||||
namespace boost
|
|
||||||
{
|
|
||||||
|
|
||||||
// boost::wrapexcept<E>
|
// boost::wrapexcept<E>
|
||||||
|
|
||||||
@ -134,17 +118,29 @@ public:
|
|||||||
|
|
||||||
virtual void rethrow() const BOOST_OVERRIDE
|
virtual void rethrow() const BOOST_OVERRIDE
|
||||||
{
|
{
|
||||||
|
#if defined( BOOST_NO_EXCEPTIONS )
|
||||||
|
|
||||||
|
boost::throw_exception( *this );
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
throw *this;
|
throw *this;
|
||||||
|
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace boost
|
// All boost exceptions are required to derive from std::exception,
|
||||||
|
// to ensure compatibility with BOOST_NO_EXCEPTIONS.
|
||||||
|
|
||||||
|
inline void throw_exception_assert_compatibility( std::exception const & ) {}
|
||||||
|
|
||||||
|
// boost::throw_exception
|
||||||
|
|
||||||
|
#if !defined( BOOST_NO_EXCEPTIONS )
|
||||||
|
|
||||||
#if defined( BOOST_EXCEPTION_DISABLE )
|
#if defined( BOOST_EXCEPTION_DISABLE )
|
||||||
|
|
||||||
namespace boost
|
|
||||||
{
|
|
||||||
|
|
||||||
template<class E> BOOST_NORETURN void throw_exception( E const & e )
|
template<class E> BOOST_NORETURN void throw_exception( E const & e )
|
||||||
{
|
{
|
||||||
throw_exception_assert_compatibility( e );
|
throw_exception_assert_compatibility( e );
|
||||||
@ -157,13 +153,7 @@ template<class E> BOOST_NORETURN void throw_exception( E const & e, boost::sourc
|
|||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace boost
|
#else // defined( BOOST_EXCEPTION_DISABLE )
|
||||||
|
|
||||||
#else // !defined( BOOST_EXCEPTION_DISABLE )
|
|
||||||
|
|
||||||
namespace boost
|
|
||||||
{
|
|
||||||
// boost::throw_exception
|
|
||||||
|
|
||||||
template<class E> BOOST_NORETURN void throw_exception( E const & e )
|
template<class E> BOOST_NORETURN void throw_exception( E const & e )
|
||||||
{
|
{
|
||||||
@ -177,12 +167,12 @@ template<class E> BOOST_NORETURN void throw_exception( E const & e, boost::sourc
|
|||||||
throw wrapexcept<E>( e, loc );
|
throw wrapexcept<E>( e, loc );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#endif // defined( BOOST_EXCEPTION_DISABLE )
|
||||||
|
|
||||||
|
#endif // !defined( BOOST_NO_EXCEPTIONS )
|
||||||
|
|
||||||
} // namespace boost
|
} // namespace boost
|
||||||
|
|
||||||
#endif // # if defined( BOOST_EXCEPTION_DISABLE )
|
|
||||||
|
|
||||||
#endif // # if defined( BOOST_NO_EXCEPTIONS )
|
|
||||||
|
|
||||||
// BOOST_THROW_EXCEPTION
|
// BOOST_THROW_EXCEPTION
|
||||||
|
|
||||||
#define BOOST_THROW_EXCEPTION(x) ::boost::throw_exception(x, BOOST_CURRENT_LOCATION)
|
#define BOOST_THROW_EXCEPTION(x) ::boost::throw_exception(x, BOOST_CURRENT_LOCATION)
|
||||||
|
@ -37,6 +37,10 @@ run throw_from_library_test.cpp lib1_throw lib2_throw lib3_throw : : : <link>sha
|
|||||||
|
|
||||||
run throw_exception_nx_test.cpp : : : <exception-handling>off ;
|
run throw_exception_nx_test.cpp : : : <exception-handling>off ;
|
||||||
run throw_exception_nx_test2.cpp : : : <exception-handling>off ;
|
run throw_exception_nx_test2.cpp : : : <exception-handling>off ;
|
||||||
|
run throw_exception_nx_test3.cpp : : : <exception-handling>off ;
|
||||||
|
|
||||||
run make_exception_ptr_test.cpp ;
|
run make_exception_ptr_test.cpp ;
|
||||||
run make_exception_ptr_test2.cpp ;
|
run make_exception_ptr_test2.cpp ;
|
||||||
|
|
||||||
|
run make_exception_ptr_nx_test.cpp : : : <exception-handling>off ;
|
||||||
|
run make_exception_ptr_nx_test2.cpp : : : <exception-handling>off ;
|
||||||
|
40
test/make_exception_ptr_nx_test.cpp
Normal file
40
test/make_exception_ptr_nx_test.cpp
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
// Copyright 2020 Peter Dimov
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// http://www.boost.org/LICENSE_1_0.txt
|
||||||
|
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
# pragma warning(disable: 4702) // unreachable code
|
||||||
|
# pragma warning(disable: 4577) // noexcept used without /EHsc
|
||||||
|
#endif
|
||||||
|
|
||||||
|
//#include <boost/exception_ptr.hpp>
|
||||||
|
|
||||||
|
#include <boost/throw_exception.hpp>
|
||||||
|
#include <boost/exception/exception.hpp>
|
||||||
|
#include <boost/shared_ptr.hpp>
|
||||||
|
#include <boost/make_shared.hpp>
|
||||||
|
|
||||||
|
typedef boost::shared_ptr<boost::exception_detail::clone_base const> exception_ptr;
|
||||||
|
|
||||||
|
template<class E> exception_ptr make_exception_ptr( E const& e )
|
||||||
|
{
|
||||||
|
return boost::make_shared< boost::wrapexcept<E> >( e );
|
||||||
|
}
|
||||||
|
|
||||||
|
class my_exception: public std::exception {};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
::make_exception_ptr( my_exception() );
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace boost
|
||||||
|
{
|
||||||
|
|
||||||
|
// shared_ptr needs this
|
||||||
|
void throw_exception( std::exception const & )
|
||||||
|
{
|
||||||
|
std::exit( 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace boost
|
42
test/make_exception_ptr_nx_test2.cpp
Normal file
42
test/make_exception_ptr_nx_test2.cpp
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
// Copyright 2020 Peter Dimov
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// http://www.boost.org/LICENSE_1_0.txt
|
||||||
|
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
# pragma warning(disable: 4702) // unreachable code
|
||||||
|
# pragma warning(disable: 4577) // noexcept used without /EHsc
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define BOOST_EXCEPTION_DISABLE
|
||||||
|
|
||||||
|
//#include <boost/exception_ptr.hpp>
|
||||||
|
|
||||||
|
#include <boost/throw_exception.hpp>
|
||||||
|
#include <boost/exception/exception.hpp>
|
||||||
|
#include <boost/shared_ptr.hpp>
|
||||||
|
#include <boost/make_shared.hpp>
|
||||||
|
|
||||||
|
typedef boost::shared_ptr<boost::exception_detail::clone_base const> exception_ptr;
|
||||||
|
|
||||||
|
template<class E> exception_ptr make_exception_ptr( E const& e )
|
||||||
|
{
|
||||||
|
return boost::make_shared< boost::wrapexcept<E> >( e );
|
||||||
|
}
|
||||||
|
|
||||||
|
class my_exception: public std::exception {};
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
::make_exception_ptr( my_exception() );
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace boost
|
||||||
|
{
|
||||||
|
|
||||||
|
// shared_ptr needs this
|
||||||
|
void throw_exception( std::exception const & )
|
||||||
|
{
|
||||||
|
std::exit( 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace boost
|
17
test/throw_exception_nx_test3.cpp
Normal file
17
test/throw_exception_nx_test3.cpp
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
// Copyright 2020 Peter Dimov
|
||||||
|
// Distributed under the Boost Software License, Version 1.0.
|
||||||
|
// http://www.boost.org/LICENSE_1_0.txt
|
||||||
|
|
||||||
|
#if defined(_MSC_VER)
|
||||||
|
# pragma warning(disable: 4702) // unreachable code
|
||||||
|
# pragma warning(disable: 4577) // noexcept used without /EHsc
|
||||||
|
#endif
|
||||||
|
|
||||||
|
// Make sure that simple inclusion does not
|
||||||
|
// require boost::throw_exception to be defined
|
||||||
|
|
||||||
|
#include <boost/throw_exception.hpp>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
}
|
Reference in New Issue
Block a user