2
0
mirror of https://github.com/boostorg/fiber.git synced 2026-02-02 08:52:07 +00:00

example regarding to exceptions

This commit is contained in:
Oliver Kowalke
2013-09-29 11:05:57 +02:00
parent 045a40e5c6
commit 500c1e605b
2 changed files with 39 additions and 0 deletions

View File

@@ -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 ;

38
examples/exception.cpp Normal file
View File

@@ -0,0 +1,38 @@
#include <cstdlib>
#include <iostream>
#include <stdexcept>
#include <string>
#include <boost/bind.hpp>
#include <boost/fiber/all.hpp>
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;
}