Mercurial > hg > orthanc
diff Core/MultiThreading/RunnableWorkersPool.cpp @ 2134:ddc75c6c712d
Avoid hard crash if not enough memory
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 09 Nov 2016 12:04:09 +0100 |
parents | b1291df2f780 |
children | a3a65de1840f |
line wrap: on
line diff
--- a/Core/MultiThreading/RunnableWorkersPool.cpp Wed Nov 09 10:21:37 2016 +0100 +++ b/Core/MultiThreading/RunnableWorkersPool.cpp Wed Nov 09 12:04:09 2016 +0100 @@ -52,25 +52,33 @@ { while (that->continue_) { - std::auto_ptr<IDynamicObject> obj(that->queue_.Dequeue(100)); - if (obj.get() != NULL) + try { - try + std::auto_ptr<IDynamicObject> obj(that->queue_.Dequeue(100)); + if (obj.get() != NULL) { IRunnableBySteps& runnable = *dynamic_cast<IRunnableBySteps*>(obj.get()); - + bool wishToContinue = runnable.Step(); - + if (wishToContinue) { // The runnable wishes to continue, reinsert it at the beginning of the queue that->queue_.Enqueue(obj.release()); } } - catch (OrthancException& e) - { - LOG(ERROR) << "Exception in a pool of working threads: " << e.What(); - } + } + catch (OrthancException& e) + { + LOG(ERROR) << "Exception while handling some runnable object: " << e.What(); + } + catch (std::bad_alloc&) + { + LOG(ERROR) << "Not enough memory to handle some runnable object"; + } + catch (...) + { + LOG(ERROR) << "Native exception while handling some runnable object"; } } }