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:
@@ -3,9 +3,11 @@
|
|||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <exception>
|
||||||
#include <componentThread.h>
|
#include <componentThread.h>
|
||||||
#include <lockSet.h>
|
#include <lockSet.h>
|
||||||
|
|
||||||
|
|
||||||
namespace smo {
|
namespace smo {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -33,8 +35,38 @@ public:
|
|||||||
std::shared_ptr<AsynchronousContinuation<OriginalCbFnT>>
|
std::shared_ptr<AsynchronousContinuation<OriginalCbFnT>>
|
||||||
lifetimePreservingConveyance);
|
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:
|
public:
|
||||||
OriginalCbFnT originalCbFn;
|
OriginalCbFnT originalCbFn;
|
||||||
|
std::exception_ptr exception;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -11,7 +11,6 @@
|
|||||||
|
|
||||||
namespace smo {
|
namespace smo {
|
||||||
|
|
||||||
|
|
||||||
template <class OriginalCbFnT>
|
template <class OriginalCbFnT>
|
||||||
class SerializedAsynchronousContinuation
|
class SerializedAsynchronousContinuation
|
||||||
: public PostedAsynchronousContinuation<OriginalCbFnT>
|
: public PostedAsynchronousContinuation<OriginalCbFnT>
|
||||||
|
|||||||
Reference in New Issue
Block a user