From 500c1e605bec4adc19afcfb05de3b93d1cac7aa7 Mon Sep 17 00:00:00 2001 From: Oliver Kowalke Date: Sun, 29 Sep 2013 11:05:57 +0200 Subject: [PATCH] example regarding to exceptions --- examples/Jamfile.v2 | 1 + examples/exception.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 examples/exception.cpp diff --git a/examples/Jamfile.v2 b/examples/Jamfile.v2 index 919d95e9..0b442d12 100644 --- a/examples/Jamfile.v2 +++ b/examples/Jamfile.v2 @@ -22,6 +22,7 @@ project boost/fiber/example/cpp03 ; exe barrier : barrier.cpp ; +exe exception : exception.cpp ; exe future : future.cpp ; exe interrupt : interrupt.cpp ; exe join : join.cpp ; diff --git a/examples/exception.cpp b/examples/exception.cpp new file mode 100644 index 00000000..9ce3e176 --- /dev/null +++ b/examples/exception.cpp @@ -0,0 +1,38 @@ +#include +#include +#include +#include + +#include + +#include + +void throw_exception() +{ + boost::this_fiber::yield(); + throw std::runtime_error("exception in fiber"); +} + +int main() +{ + boost::fibers::round_robin ds; + boost::fibers::set_scheduling_algorithm( & ds); + + try + { + boost::fibers::fiber f(throw_exception); + f.join(); + + std::cout << "done." << std::endl; + + return EXIT_SUCCESS; + } + catch ( boost::fibers::fiber_interrupted const&) + { std::cerr << "interrupted" << std::endl; } + catch ( std::exception const& e) + { std::cerr << "exception: " << e.what() << std::endl; } + catch (...) + { std::cerr << "unhandled exception" << std::endl; } + + return EXIT_FAILURE; +}