/// <summary> /// Handle errors for the promise. /// </summary> public IPromise Catch(Action <Exception> onRejected) { // Argument.NotNull(() => onRejected); if (CurState == PromiseState.Resolved) { return(this); } else if (CurState == PromiseState.Rejected) { try { onRejected(rejectionException); return(Promise.Resolved()); } catch (Exception ex) { return(Promise.RejectedStatic(ex)); } } else { return(CatchPending(onRejected)); } }
/// <summary> /// Add a resolved callback and a rejected callback. /// </summary> public IPromise Then(Action <PromisedT> onResolved, Action <Exception> onRejected) { if (CurState == PromiseState.Resolved) { try { onResolved(resolveValue); return(Promise.Resolved()); } catch (Exception ex) { return(Promise.Rejected(ex)); } } else if (CurState == PromiseState.Rejected) { try { if (onRejected != null) { onRejected(rejectionException); return(Promise.RejectedStatic(rejectionException)); } else { return(Promise.RejectedStatic(rejectionException)); } } catch (Exception ex) { return(Promise.RejectedStatic(ex)); } } else { return(ThenPending(onResolved, onRejected)); } }
/// <summary> /// Handle errors for the promise. /// </summary> public IPromise <PromisedT> Catch(Func <Exception, PromisedT> onRejected) { if (CurState == PromiseState.Resolved) { return(this); } else if (CurState == PromiseState.Rejected) { try { PromisedT retVal = onRejected(rejectionException); return(Promise <PromisedT> .Resolved(retVal)); } catch (Exception ex) { return(Promise <PromisedT> .RejectedStatic(ex)); } } else { return(CatchPending(onRejected)); } }
/// <summary> /// Handle errors for the promise. /// </summary> public IPromise Catch(Action <Exception> onRejected) { if (CurState == PromiseState.Resolved) { return(Promise.Resolved()); } else if (CurState == PromiseState.Rejected) { try { onRejected(rejectionException); return(Promise.Resolved()); } catch (Exception ex) { return(Promise.RejectedStatic(ex)); } } else { return(CatchPending(onRejected)); } }