Opened 7 years ago

Closed 6 years ago

Last modified 5 years ago

#12105 closed Feature Requests (wontfix)

Support std::exception_ptr in boost::promise set_exception ??

Reported by: RelicOfTesla@… Owned by: Anthony Williams
Milestone: Component: thread
Version: Boost 1.60.0 Severity: Problem
Keywords: Cc:

Description

MSC_VER=1600,BOOST_VER=106000 invalid catch

void foo_lang_test()
{
	printf("MSC_VER=%d,BOOST_VER=%d\n", _MSC_VER , BOOST_VERSION );
	boost::promise<void> pp;
	try
	{
		throw std::runtime_error("aa");
	}
	catch(...)
	{
		pp.set_exception(std::current_exception());
	}
	try
	{
		pp.get_future().get();
	}
	catch(std::exception& e)
	{
		printf("catch %s\n", e.what());
	}
	catch(...)
	{
		printf("invalid catch\n");
	}
}

Change History (3)

comment:1 by John Maddock, 7 years ago

Component: TR1thread
Owner: changed from John Maddock to Anthony Williams

comment:2 by viboes, 6 years ago

Milestone: To Be Determined
Resolution: wontfix
Status: newclosed
Type: BugsFeature Requests

I can not take this in account unless boost::exception_ptr accepts std::exception_ptr

comment:3 by joseph@…, 5 years ago

Is there some reason you can't add a #define to use std::exception_ptr instead of boost::exception_ptr? The 2 are totally incompatible so any system libraries using std::exception_ptr (such as ISO/IEC TS 22277:2017 coroutines) become a real burden to use with boost future (which has many wonderful features std::future does not). There does not appear to be a way to reliably convert between std::exception_ptr and boost::exception_ptr and the limited method I have found requires throwing 2 additional times which is really wasteful.

namespace boost
{
  template <>
  inline
    exception_ptr copy_exception(std::exception_ptr const &ex)
  {
    try {
      std::rethrow_exception(ex);
    }
    catch (const std::exception& e) {
      try {
        throw boost::enable_current_exception(e);
      }
      catch (...) {
        return boost::current_exception();
      }
    }
    catch (...) {
      try {
        throw boost::enable_current_exception(std::runtime_error("unknown exception"));
      }
      catch (...) {
        return boost::current_exception();
      }
    }
  }
}
Note: See TracTickets for help on using tickets.