Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在并行区域内使用“抛出异常”可以吗?
当一个线程抛出异常时,其余线程会发生什么?
代码:
#pragma omp parallel for for(int i = 0; i < n; i++) { if(arr[i] < 0) throw BadParameter("bad array value"); }
在并行区域内执行的 throw 必须导致在同一并行区域内恢复执行,并且必须由引发异常的同一线程捕获。
否则它将传播到未处理的异常中。