The default ActiveStarter static start method does not catch NoThreadAvailableExceptions from the threadpool.
See:
https://github.com/pocoproject/poco/blo ... rter.h#L59
Ideally, I would like to catch that error and then call the error method on the associated ActiveResult (passing in the NoThreadAvailableExceptions exception). Intra-thread Exceptions are caught and appropriately set from WITHIN the run method of ActiveRunnable, allowing the ActiveResult to fail by calling its error(*) method:
https://github.com/pocoproject/poco/blo ... able.h#L80
But I'm looking for a way to call error(*) on an ActiveResult BEFORE its run() method is called (i.e. due to a NoThreadAvailableException or perhaps another arbitrary exception).
https://github.com/pocoproject/poco/blo ... hod.h#L114
I can think of several work arounds, including checking the threadpool's thread availability before calling the ActiveMethod (risky in a multi-threaded environment), or overriding the ActiveMethod::operator() method, or even writing a custom StarterType that casts the ActiveRunnableBase::Ptr to the derived ActiveRunnable type and then accesses it's ActiveResult, but that all seems a little bit sloppy, when the rest of the Active framework seems so tidy.
It seems like the tidiest way would be for the StarterClass to throw an exception that the the ActiveMethod could catch and pass to the ActiveResult -- something like:
- Code: Select all
ActiveResultType operator () (const ArgType& arg)
/// Invokes the ActiveMethod.
{
ActiveResultType result(new ActiveResultHolder<ResultType>());
ActiveRunnableBase::Ptr pRunnable(new ActiveRunnableType(_pOwner, _method, arg, result));
try {
StarterType::start(_pOwner, pRunnable);
} catch(Exception& exc) {
result.error(exc);
return result;
} catch(std::exception& e) {
result.error(e.what());
return result;
} catch( ... ) {
result.error("unknown exception");
return result;
}
return result;
}
Anyway, advice for how I might catch exceptions from WITHIN the StarterType static method class and passing them to the ActiveResult are appreciated.
Thanks!
Christopher





