• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include "rxcpp/rx.hpp"
2 namespace rxu=rxcpp::util;
3 
4 #include "rxcpp/rx-test.hpp"
5 #include "catch.hpp"
6 
7 #if RXCPP_USE_EXCEPTIONS
8 SCENARIO("composite_exception sample"){
9     printf("//! [composite_exception sample]\n");
10     auto o1 = rxcpp::observable<>::error<int>(std::runtime_error("Error from source o1\n"));
11     auto o2 = rxcpp::observable<>::error<int>(std::runtime_error("Error from source o2\n"));
__anone45e37500102(int) 12     auto o3 = rxcpp::observable<>::timer(std::chrono::milliseconds(5)).map([](int) {return 3;});
13     auto values = o1.merge_delay_error(o2, o3);
14     values.
15         subscribe(
__anone45e37500202(int v)16             [](int v){printf("OnNext: %d\n", v);},
__anone45e37500302(std::exception_ptr composite_e) 17             [](std::exception_ptr composite_e) {
18                 printf("OnError %s\n", rxu::what(composite_e).c_str());
19                 try { std::rethrow_exception(composite_e); }
20                 catch(rxcpp::composite_exception const &ce) {
21                     for(std::exception_ptr particular_e : ce.exceptions) {
22 
23                         try{ std::rethrow_exception(particular_e); }
24                         catch(std::runtime_error const &error) { printf(" *** %s\n", error.what()); }
25 
26                     }
27                 }
28             },
__anone45e37500402()29             [](){printf("OnCompleted\n");}
30         );
31     printf("//! [composite_exception sample]\n");
32 }
33 #endif
34