veda
veda

Reputation: 6604

Is it fine to use "throw exception" inside parallel region?

Will it be fine to use "Throw exception" inside the parallel region?

What will happen to rest of the threads when one thread throws an exception?

code:

#pragma omp parallel for
for(int i = 0; i < n; i++)
{
     if(arr[i] < 0)
       throw BadParameter("bad array value");
}

Upvotes: 3

Views: 460

Answers (1)

Anycorn
Anycorn

Reputation: 51525

A throw executed inside a parallel region must cause execution to resume within the same parallel region, and it must be caught by the same thread that threw the exception.

Otherwise it will propagate into unhandled exception.

Upvotes: 5

Related Questions