From e6918187568dbd01842d8d1d2c808ce16a894239 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 21 Apr 2024 13:54:28 +0200 Subject: Adding upstream version 18.2.2. Signed-off-by: Daniel Baumann --- src/boost/libs/context/example/fiber/throw.cpp | 45 ++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/boost/libs/context/example/fiber/throw.cpp (limited to 'src/boost/libs/context/example/fiber/throw.cpp') diff --git a/src/boost/libs/context/example/fiber/throw.cpp b/src/boost/libs/context/example/fiber/throw.cpp new file mode 100644 index 000000000..e5f1d6f65 --- /dev/null +++ b/src/boost/libs/context/example/fiber/throw.cpp @@ -0,0 +1,45 @@ + +// Copyright Oliver Kowalke 2016. +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) + +#include +#include +#include +#include +#include + +#include + +namespace ctx = boost::context; + +struct my_exception : public std::runtime_error { + ctx::fiber f; + my_exception( ctx::fiber && f_, std::string const& what) : + std::runtime_error{ what }, + f{ std::move( f_) } { + } +}; + +int main() { + ctx::fiber f{[](ctx::fiber && f) ->ctx::fiber { + std::cout << "entered" << std::endl; + try { + f = std::move( f).resume(); + } catch ( my_exception & ex) { + std::cerr << "my_exception: " << ex.what() << std::endl; + return std::move( ex.f); + } + return {}; + }}; + f = std::move( f).resume(); + f = std::move( f).resume_with([](ctx::fiber && f) ->ctx::fiber { + throw my_exception(std::move( f), "abc"); + return {}; + }); + + std::cout << "main: done" << std::endl; + + return EXIT_SUCCESS; +} -- cgit v1.2.3