|
| 1 | +<cxx-clause id="parallel.exceptions"> |
| 2 | + <h1>Parallel exceptions</h1> |
| 3 | + <cxx-section id="parallel.exceptions.behavior"> |
| 4 | + <h1>Exception reporting behavior</h1> |
| 5 | + <p> |
| 6 | + If temporary memory resources are required by the algorithm and none are available, |
| 7 | + the algorithm throws a `std::bad_alloc` exception. |
| 8 | + </p> |
| 9 | + <p> |
| 10 | + During the execution of a standard parallel algorithm, if the application of a function |
| 11 | + object terminates with an uncaught exception, the behavior of the program is determined |
| 12 | + by the type of execution policy used to invoke the algorithm: |
| 13 | + |
| 14 | + <ul> |
| 15 | + <li> |
| 16 | + If the execution policy object is of type <code>vector_execution_policy</code>, |
| 17 | + <code>std::terminate</code> shall be called. |
| 18 | + </li> |
| 19 | + <li> |
| 20 | + If the execution policy object is of type <code>sequential_execution_policy</code> or |
| 21 | + <code>parallel_execution_policy</code>, the execution of the algorithm terminates with an |
| 22 | + <code>exception_list</code> exception. All uncaught exceptions thrown during |
| 23 | + the application of user-provided function objects shall be contained in the |
| 24 | + <code>exception_list</code>. |
| 25 | + |
| 26 | + <cxx-note> |
| 27 | + For example, the number of invocations of the user-provided function object in |
| 28 | + <code>for_each</code> is unspecified. When <code>for_each</code> is executed sequentially, |
| 29 | + only one exception will be contained in the <code>exception_list</code> object. |
| 30 | + </cxx-note> |
| 31 | + |
| 32 | + <cxx-note> |
| 33 | + These guarantees imply that, unless the algorithm has failed to allocate memory and |
| 34 | + terminated with <code>std::bad_alloc</code>, all exceptions thrown during the execution of |
| 35 | + the algorithm are communicated to the caller. It is unspecified whether an algorithm implementation will "forge ahead" after |
| 36 | + encountering and capturing a user exception. |
| 37 | + </cxx-note> |
| 38 | + |
| 39 | + <cxx-note> |
| 40 | + The algorithm may terminate with the <code>std::bad_alloc</code> exception even if one or more |
| 41 | + user-provided function objects have terminated with an exception. For example, this can happen when an algorithm fails to allocate memory while |
| 42 | + creating or adding elements to the <code>exception_list</code> object. |
| 43 | + </cxx-note> |
| 44 | + </li> |
| 45 | + |
| 46 | + <li> |
| 47 | + If the execution policy object is of any other type, the behavior is implementation-defined. |
| 48 | + </li> |
| 49 | + </ul> |
| 50 | + </p> |
| 51 | + </cxx-section> |
| 52 | +</cxx-clause> |
0 commit comments