V1303. The 'foo' function which throws an exception cannot be used in a parallel section outside of a try..catch block

The analyzer found an error relating to throwing an exception from a parallel block. According to OpenMP specification, if you use exceptions inside a parallel block all these exceptions should be processed inside this block. The analyzer warns about the call of a function which is marked as throwing exceptions in a parallel block and which is not protected by try..catch block.

When an exception is thrown from ExceptionFoo function the example given below leads to incorrect program's behavior and most likely to a program crash:

void ExceptionFoo() throw(...) { }
void foo1303(ptrdiff_t n)
{
  #pragma omp parallel for
  for (ptrdiff_t i = 0; i < n; ++i)
  {
    //...
    ExceptionFoo();
    //...
  }
}

Correction of the code lies in processing exceptions inside the parallel block and transferring information about the error through other mechanisms. Below the two variants of the corrected function are given:

void foo1303_fixed(ptrdiff_t n)
{
  #pragma omp parallel for
  for (ptrdiff_t i = 0; i != n; ++i)
  {
    try {
      //...
      ExceptionFoo();
      //...
    }
    catch (...) {
      // process exception
    }
  }
}

You should keep in mind that functions not marked as throw(...) can also generate exceptions. But VivaMP analyzer doesn't consider calling them unsafe. It is made to generate diagnostic messages in a reasonable number. Otherwise any code containing function call will be considered unsafe. The following principle is used:

void foo(); - suppose it don't throw an exception

void foo() throw();- doesn't throw an exception

void foo() throw(...); - throws an exception