Async: Add exception bubbling

CONT_SET_EXC: Set exception on the continuation, to be rethrown
	by the caller.
CONT_SET_EXC_AND_RET: Convenience which returns immediately
	after setting the exception.
This commit is contained in:
2025-09-21 14:17:23 -04:00
parent 1e2cc5ef16
commit dbc9569775
2 changed files with 32 additions and 1 deletions
+32
View File
@@ -3,9 +3,11 @@
#include <functional>
#include <memory>
#include <exception>
#include <componentThread.h>
#include <lockSet.h>
namespace smo {
/**
@@ -33,8 +35,38 @@ public:
std::shared_ptr<AsynchronousContinuation<OriginalCbFnT>>
lifetimePreservingConveyance);
/** EXPLANATION:
* When an exception is thrown in a an async callee, which pertains to an
* error in the data given by the caller, we ought not to throw the
* exception within the callee. Instead, we should store the exception
* in the continuation object and return it to the caller.
*
* The caller should then call checkException() to rethrow it on its
* own stack.
*
* This macro should be used by the caller to bubble the exception to the
* caller.
*/
#define CONT_SET_EXC(continuation, type, exc_obj) \
(continuation)->exception = std::make_exception_ptr<type>(exc_obj)
#define CONT_SET_EXC_AND_RET(continuation, type, exc_obj) \
do { \
(continuation)->exception = std::make_exception_ptr<type>(exc_obj); \
return; \
} while(0)
// Call this in the caller to rethrow the exception.
void checkException()
{
if (exception)
{ std::rethrow_exception(exception); }
}
public:
OriginalCbFnT originalCbFn;
std::exception_ptr exception;
};
/**
@@ -11,7 +11,6 @@
namespace smo {
template <class OriginalCbFnT>
class SerializedAsynchronousContinuation
: public PostedAsynchronousContinuation<OriginalCbFnT>