Compare commits

...

8 Commits

Author SHA1 Message Date
d664eb9b51 Rework as esp-idf component 2023-11-23 17:17:05 +01:00
e2faee265d Merge pull request #43 from boostorg/pr/current-exception
Prefer using std::current_exception when available
2022-01-25 19:40:04 -08:00
7df9fc8a85 Merge pull request #41 from boostorg/pr/copy-exception
Use enable_current_exception instead of wrapexcept in copy_exception
2022-01-25 19:39:39 -08:00
9259706f08 Disable exception_ptr_test2 when exceptions aren't enabled 2022-01-26 01:49:45 +02:00
eafe6dbd5c Prefer using std::current_exception when available (refs #42) 2022-01-26 01:12:54 +02:00
941754ed23 Add exception_ptr_test2.cpp 2022-01-26 01:07:46 +02:00
0d205cd71f Use enable_current_exception instead of wrapexcept in copy_exception 2022-01-25 19:54:15 +02:00
b8e9e98b33 Categorized as "Error-handling" in meta/libraries.json 2021-11-06 15:03:14 -07:00
5 changed files with 160 additions and 6 deletions

View File

@ -2,6 +2,8 @@
# Distributed under the Boost Software License, Version 1.0.
# https://www.boost.org/LICENSE_1_0.txt
if(NOT DEFINED IDF_TARGET)
cmake_minimum_required(VERSION 3.5...3.20)
project(boost_exception VERSION "${BOOST_SUPERPROJECT_VERSION}" LANGUAGES CXX)
@ -30,3 +32,26 @@ if(BUILD_TESTING AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/CMakeLists.txt")
add_subdirectory(test)
endif()
else()
FILE(GLOB_RECURSE headers include/*.h include/*.hpp)
idf_component_register(
SRCS
${headers}
# src/clone_current_exception_non_intrusive.cpp
INCLUDE_DIRS
include
REQUIRES
boost_assert
boost_config
boost_core
boost_smart_ptr
boost_throw_exception
boost_tuple
boost_type_traits
)
endif()

View File

@ -112,14 +112,24 @@ boost
}
};
namespace
exception_detail
{
template <class E>
inline
exception_ptr
copy_exception_impl( E const & e )
{
return exception_ptr(boost::make_shared<E>(e));
}
}
template <class E>
inline
exception_ptr
copy_exception( E const & e )
{
E cp = e;
exception_detail::copy_boost_exception(&cp, &e);
return exception_ptr(boost::make_shared<wrapexcept<E> >(cp));
return exception_detail::copy_exception_impl(boost::enable_current_exception(e));
}
template <class T>
@ -385,6 +395,9 @@ boost
{
return exception_ptr(shared_ptr<exception_detail::clone_base const>(e.clone()));
}
#ifdef BOOST_NO_CXX11_HDR_EXCEPTION
catch(
std::domain_error & e )
{
@ -457,19 +470,19 @@ boost
{
return exception_detail::current_exception_std_exception(e);
}
#ifdef BOOST_NO_CXX11_HDR_EXCEPTION
// this case can be handled losslesly with std::current_exception() (see below)
catch(
std::exception & e )
{
return exception_detail::current_exception_unknown_std_exception(e);
}
#endif
catch(
boost::exception & e )
{
return exception_detail::current_exception_unknown_boost_exception(e);
}
#endif // #ifdef BOOST_NO_CXX11_HDR_EXCEPTION
catch(
... )
{

View File

@ -7,6 +7,7 @@
"description": "The Boost Exception library supports transporting of arbitrary data in exception objects, and transporting of exceptions between threads.",
"documentation": "doc/boost-exception.html",
"category": [
"Error-handling",
"Emulation"
],
"maintainers": [

View File

@ -41,6 +41,7 @@ run no_exceptions_test.cpp : : : <exception-handling>off ;
run errinfos_test.cpp : : : <exception-handling>on ;
run exception_ptr_test.cpp/<define>BOOST_ENABLE_NON_INTRUSIVE_EXCEPTION_PTR ../../thread/src/tss_null.cpp /boost/exception /boost//thread : : : <threading>multi <exception-handling>on : non_intrusive_exception_ptr_test ;
run exception_ptr_test.cpp ../../thread/src/tss_null.cpp /boost//thread : : : <threading>multi <exception-handling>on ;
run exception_ptr_test2.cpp ;
lib visibility_test_lib : visibility_test_lib.cpp : <visibility>hidden <exception-handling>on ;
run visibility_test.cpp visibility_test_lib/<link>shared : : : <visibility>hidden <exception-handling>on ;

View File

@ -0,0 +1,114 @@
// Copyright 2022 Peter Dimov
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt
#include <boost/config.hpp>
#if defined(BOOST_NO_EXCEPTIONS)
#include <boost/config/pragma_message.hpp>
BOOST_PRAGMA_MESSAGE( "Skipping test because BOOST_NO_EXCEPTIONS is defined" )
int main() {}
#elif defined(BOOST_NO_CXX11_HDR_EXCEPTION)
#include <boost/config/pragma_message.hpp>
BOOST_PRAGMA_MESSAGE( "Skipping test because BOOST_NO_CXX11_HDR_EXCEPTION is defined" )
int main() {}
#else
#include <boost/exception_ptr.hpp>
#include <boost/exception/exception.hpp>
#include <boost/core/lightweight_test.hpp>
#include <exception>
#include <new>
#include <stdexcept>
class my_exception
{
};
class my_exception2: public std::exception
{
};
class my_exception3: public std::bad_alloc
{
};
class my_exception4: public std::exception, public boost::exception
{
};
class my_exception5: public std::logic_error, public virtual boost::exception
{
public:
my_exception5(): std::logic_error( "" ) {}
};
int main()
{
try
{
throw my_exception();
}
catch( ... )
{
boost::exception_ptr p = boost::current_exception();
BOOST_TEST_THROWS( boost::rethrow_exception( p ), my_exception );
}
try
{
throw my_exception2();
}
catch( ... )
{
boost::exception_ptr p = boost::current_exception();
BOOST_TEST_THROWS( boost::rethrow_exception( p ), my_exception2 );
BOOST_TEST_THROWS( boost::rethrow_exception( p ), std::exception );
}
try
{
throw my_exception3();
}
catch( ... )
{
boost::exception_ptr p = boost::current_exception();
BOOST_TEST_THROWS( boost::rethrow_exception( p ), my_exception3 );
BOOST_TEST_THROWS( boost::rethrow_exception( p ), std::bad_alloc );
}
try
{
throw my_exception4();
}
catch( ... )
{
boost::exception_ptr p = boost::current_exception();
BOOST_TEST_THROWS( boost::rethrow_exception( p ), my_exception4 );
BOOST_TEST_THROWS( boost::rethrow_exception( p ), std::exception );
BOOST_TEST_THROWS( boost::rethrow_exception( p ), boost::exception );
}
try
{
throw my_exception5();
}
catch( ... )
{
boost::exception_ptr p = boost::current_exception();
BOOST_TEST_THROWS( boost::rethrow_exception( p ), my_exception5 );
BOOST_TEST_THROWS( boost::rethrow_exception( p ), std::logic_error );
BOOST_TEST_THROWS( boost::rethrow_exception( p ), boost::exception );
}
return boost::report_errors();
}
#endif