31 #ifndef LEDGER_CORE_TRY_HPP 32 #define LEDGER_CORE_TRY_HPP 35 #include <jni/jni/djinni_support.hpp> 39 #include "optional.hpp" 41 #include "Exception.hpp" 44 #include <boost/exception/diagnostic_information.hpp> 71 void success(
const T& v) {
75 const T& getValue()
const {
76 return _value.value();
80 return _exception.value();
83 bool isFailure()
const {
84 return _exception ? true :
false;
86 bool isSuccess()
const {
87 return _value ? true :
false;
89 bool isComplete()
const {
90 return isSuccess() || isFailure();
105 const T& getOrThrow()
const {
112 const T& getOrThrowException()
const {
114 throw U(getFailure().getMessage());
120 return Try<T>(code, getFailure().getMessage());
140 static const Try<T> from(std::function<T ()> lambda) {
143 result.success(lambda());
157 template <
typename T>
161 Try<T> make_try(std::function<T ()> lambda) {
168 #endif //LEDGER_CORE_TRY_HPP
Definition: Option.hpp:49
Definition: djinni_support.hpp:112
Definition: Account.cpp:8
ErrorCode
Definition: ErrorCode.hpp:20
Definition: optional.hpp:177
Definition: Exception.hpp:45