diff --git a/include/execq/internal/ExecutionQueue.h b/include/execq/internal/ExecutionQueue.h index 329741b..9937339 100644 --- a/include/execq/internal/ExecutionQueue.h +++ b/include/execq/internal/ExecutionQueue.h @@ -186,10 +186,13 @@ execq::impl::Task execq::impl::ExecutionQueue::nextTask() template void execq::impl::ExecutionQueue::execute(T&& object, std::promise& promise, const std::atomic_bool& canceled) { +#if defined(__cpp_exceptions) try { +#endif m_executor(canceled, std::move(object)); promise.set_value(); +#if defined(__cpp_exceptions) } catch(...) { @@ -200,15 +203,19 @@ void execq::impl::ExecutionQueue::execute(T&& object, std::promise& catch(...) {} // set_exception() may throw too } +#endif } template template void execq::impl::ExecutionQueue::execute(T&& object, std::promise& promise, const std::atomic_bool& canceled) { +#if defined(__cpp_exceptions) try { +#endif promise.set_value(m_executor(canceled, std::move(object))); +#if defined(__cpp_exceptions) } catch(...) { @@ -219,6 +226,7 @@ void execq::impl::ExecutionQueue::execute(T&& object, std::promise& pro catch(...) {} // set_exception() may throw too } +#endif } template diff --git a/src/execq.cpp b/src/execq.cpp index a677081..e891196 100644 --- a/src/execq.cpp +++ b/src/execq.cpp @@ -25,6 +25,10 @@ #include "execq.h" #include "ExecutionStream.h" +#if !defined(__cpp_exceptions) +# include +#endif + namespace { uint32_t GetOptimalThreadCount() @@ -51,7 +55,12 @@ std::shared_ptr execq::CreateExecutionPool(const uint32_t { if (!threadCount) { +#if defined(__cpp_exceptions) throw std::runtime_error("Failed to create IExecutionPool: thread count could not be zero."); +#else + (void)std::fprintf(stderr, "Failed to create IExecutionPool: thread count could not be zero."); + abort(); +#endif } else if (threadCount == 1) {