7 #ifndef TREELITE_DETAIL_OMP_EXCEPTION_H_
8 #define TREELITE_DETAIL_OMP_EXCEPTION_H_
23 std::exception_ptr omp_exception_;
31 template <
typename Function,
typename... Parameters>
32 void Run(Function f, Parameters... params) {
36 std::lock_guard<std::mutex> lock(mutex_);
37 if (!omp_exception_) {
38 omp_exception_ = std::current_exception();
40 }
catch (std::exception& ex) {
41 std::lock_guard<std::mutex> lock(mutex_);
42 if (!omp_exception_) {
43 omp_exception_ = std::current_exception();
52 if (this->omp_exception_) {
53 std::rethrow_exception(this->omp_exception_);
OMP Exception class catches, saves and rethrows exception from OMP blocks.
Definition: omp_exception.h:20
void Run(Function f, Parameters... params)
Parallel OMP blocks should be placed within Run to save exception.
Definition: omp_exception.h:32
void Rethrow()
should be called from the main thread to rethrow the exception
Definition: omp_exception.h:51
Exception class used throughout the Treelite codebase.
Definition: contiguous_array.h:14
Exception class that will be thrown by Treelite.
Definition: error.h:18