|
| 1 | +/*-------------------------------------------------------------------- |
| 2 | + (C) Copyright 2006-2013 Barcelona Supercomputing Center |
| 3 | + Centro Nacional de Supercomputacion |
| 4 | +
|
| 5 | + This file is part of Mercurium C/C++ source-to-source compiler. |
| 6 | +
|
| 7 | + See AUTHORS file in the top level directory for information |
| 8 | + regarding developers and contributors. |
| 9 | +
|
| 10 | + This library is free software; you can redistribute it and/or |
| 11 | + modify it under the terms of the GNU Lesser General Public |
| 12 | + License as published by the Free Software Foundation; either |
| 13 | + version 3 of the License, or (at your option) any later version. |
| 14 | +
|
| 15 | + Mercurium C/C++ source-to-source compiler is distributed in the hope |
| 16 | + that it will be useful, but WITHOUT ANY WARRANTY; without even the |
| 17 | + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR |
| 18 | + PURPOSE. See the GNU Lesser General Public License for more |
| 19 | + details. |
| 20 | +
|
| 21 | + You should have received a copy of the GNU Lesser General Public |
| 22 | + License along with Mercurium C/C++ source-to-source compiler; if |
| 23 | + not, write to the Free Software Foundation, Inc., 675 Mass Ave, |
| 24 | + Cambridge, MA 02139, USA. |
| 25 | +--------------------------------------------------------------------*/ |
| 26 | + |
| 27 | +// RUN: %oss-cxx-compile-and-run | FileCheck %s |
| 28 | + |
| 29 | +#include <iostream> // std::cout |
| 30 | +#include <exception> // std::exception_ptr, std::current_exception, std::rethrow_exception |
| 31 | +#include <stdexcept> // std::logic_error |
| 32 | + |
| 33 | +int main () { |
| 34 | + std::exception_ptr p; // shared between tasks because the second one needs it |
| 35 | + // for rethrow |
| 36 | + #pragma oss task shared(p) |
| 37 | + { |
| 38 | + try { |
| 39 | + throw std::logic_error("some logic_error exception"); // throws |
| 40 | + } catch(const std::exception& e) { |
| 41 | + p = std::current_exception(); |
| 42 | + std::cout << "exception caught, but continuing...\n"; |
| 43 | + } |
| 44 | + } |
| 45 | + #pragma oss taskwait |
| 46 | + |
| 47 | + std::cout << "(after exception)\n"; |
| 48 | + |
| 49 | + #pragma oss task |
| 50 | + { |
| 51 | + try { |
| 52 | + std::rethrow_exception (p); |
| 53 | + } catch (const std::exception& e) { |
| 54 | + std::cout << "exception caught: " << e.what() << '\n'; |
| 55 | + } |
| 56 | + } |
| 57 | + #pragma oss taskwait |
| 58 | + return 0; |
| 59 | +} |
| 60 | + |
| 61 | +// CHECK: exception caught, but continuing... |
| 62 | +// CHECK-NEXT: (after exception) |
| 63 | +// CHECK-NEXT: exception caught: some logic_error exception |
0 commit comments