-
Marc Celani authored
Summary: folly::exception_wrapper is a different take on std::exception_ptr to suit a specific use case. The good: std::exception_ptr is not templated, so it can easily be used in different classes without template creep. You can pass errors around between threads or simply between modules. Rethrowing the exception throws the *proper* derived class exception, not some base class. The bad: Getting access to the exception requires throwing, which is expensive. Many users of popular frameworks that take advantage of std::exception_ptr check if the exception is set, and if so do some error handling without actually knowing the type of the exception or logging its message, just to avoid the cost of rethrowing the exception. The ugly: Creating an exception_ptr requires throwing the exception as least once. This is bad in the performance sensitive case where users will not even inspect the exception. This class takes advantage of the good while avoiding the requirement to throw. By using a templated deleter and thrower function, we can create an exception_wrapper which is properly managed, can be thrown, and can be retrieved as a void* with a get() function. Users that previously caught exceptions are now able to dynamically cast to different exception types they formerly caught to avoid the unwind cost while still getting details about the error. Test Plan: unit test Reviewed By: davejwatson@fb.com FB internal diff: D1305470 @override-unit-failures
ad55cd0e