diff options
author | Valery Kopylov <v-valkop@microsoft.com> | 2015-06-02 15:05:41 +0300 |
---|---|---|
committer | Valery Kopylov <v-valkop@microsoft.com> | 2015-06-09 13:00:53 +0300 |
commit | a217bbaeee8d5641cb10dbfdc253cb93d6eb7ba7 (patch) | |
tree | 186f3adc98615b8a300df607d9b864873adbae30 /Rx | |
parent | 8f300c39206fc3275778d2cd761c9772bf0741ac (diff) | |
download | RxCpp-a217bbaeee8d5641cb10dbfdc253cb93d6eb7ba7.tar.gz |
Throw an exception when reducing an empty blocking_observable.
Diffstat (limited to 'Rx')
-rw-r--r-- | Rx/v2/src/rxcpp/rx-observable.hpp | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/Rx/v2/src/rxcpp/rx-observable.hpp b/Rx/v2/src/rxcpp/rx-observable.hpp index 7d048f6..5ed5ec0 100644 --- a/Rx/v2/src/rxcpp/rx-observable.hpp +++ b/Rx/v2/src/rxcpp/rx-observable.hpp @@ -281,19 +281,23 @@ public: rxu::maybe<T> result; composite_subscription cs; subscribe(cs, [&](T v){result.reset(v); cs.unsubscribe();}); - if (result.empty()) abort(); + if (result.empty()) throw std::runtime_error("No elements"); return result.get(); } T last() const { rxu::maybe<T> result; subscribe([&](T v){result.reset(v);}); - if (result.empty()) abort(); + if (result.empty()) throw std::runtime_error("No elements"); return result.get(); } int count() const { - return source.count().as_blocking().last(); + rxu::maybe<T> result; + source.count().as_blocking().subscribe( + [&](T v){result.reset(v);}, + [](std::exception_ptr){result.reset(0);}); + return result.get(); } T sum() const { return source.sum().as_blocking().last(); |