diff --git a/include/asynchronousContinuation.h b/include/asynchronousContinuation.h index 95f2793..407318d 100644 --- a/include/asynchronousContinuation.h +++ b/include/asynchronousContinuation.h @@ -3,9 +3,11 @@ #include #include +#include #include #include + namespace smo { /** @@ -33,8 +35,38 @@ public: std::shared_ptr> 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(exc_obj) + + #define CONT_SET_EXC_AND_RET(continuation, type, exc_obj) \ + do { \ + (continuation)->exception = std::make_exception_ptr(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; }; /** diff --git a/include/serializedAsynchronousContinuation.h b/include/serializedAsynchronousContinuation.h index e632ebf..a8cded8 100644 --- a/include/serializedAsynchronousContinuation.h +++ b/include/serializedAsynchronousContinuation.h @@ -11,7 +11,6 @@ namespace smo { - template class SerializedAsynchronousContinuation : public PostedAsynchronousContinuation