當前位置: 首頁>>代碼示例>>C#>>正文


C# Promise.Catch方法代碼示例

本文整理匯總了C#中Promise.Catch方法的典型用法代碼示例。如果您正苦於以下問題:C# Promise.Catch方法的具體用法?C# Promise.Catch怎麽用?C# Promise.Catch使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Promise的用法示例。


在下文中一共展示了Promise.Catch方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: can_reject_simple_promise

		public void can_reject_simple_promise() {
			var ex = new Exception();
			var promise = new Promise<int>(ex);

			var errors = 0;
			promise.Catch(e => {
				Assert.Equal(ex, e);
				++errors;
			});

			Assert.Equal(1, errors);
		}
開發者ID:zon,項目名稱:cardinal,代碼行數:12,代碼來源:PromiseTests.cs

示例2: ExceptionThrownDuringResolverRejectsProimse

        public void ExceptionThrownDuringResolverRejectsProimse()
        {
            var ex = new Exception();
            var promise = new Promise<int>((resolve, reject) =>
            {
                throw ex;
            });

            var completed = 0;
            promise.Catch(e =>
            {
                Assert.AreEqual(ex, e);
                ++completed;
            });

            Assert.AreEqual(1, completed);
        }
開發者ID:rob-blackbourn,項目名稱:JetBlack.Promises,代碼行數:17,代碼來源:PromiseFixture.cs

示例3: CanRejectPromiseViaRejectFunction

        public void CanRejectPromiseViaRejectFunction()
        {
            var ex = new Exception();
            var promise = new Promise<int>((resolve, reject) => reject(ex));

            var completed = 0;
            promise.Catch(e =>
            {
                Assert.AreEqual(ex, e);
                ++completed;
            });

            Assert.AreEqual(1, completed);
        }
開發者ID:rob-blackbourn,項目名稱:JetBlack.Promises,代碼行數:14,代碼來源:PromiseFixture.cs

示例4: ErrorHandlerIsNotInvokedForResolvedPromised

        public void ErrorHandlerIsNotInvokedForResolvedPromised()
        {
            var promise = new Promise<int>();

            promise.Catch(e =>
            {
                throw new ApplicationException("This shouldn't happen");
            });

            promise.Resolve(5);
        }
開發者ID:rob-blackbourn,項目名稱:JetBlack.Promises,代碼行數:11,代碼來源:PromiseFixture.cs

示例5: CanRejectPromiseAndTriggerErrorHandlerWithRegistrationAfterReject

        public void CanRejectPromiseAndTriggerErrorHandlerWithRegistrationAfterReject()
        {
            var promise = new Promise<int>();

            var ex = new ApplicationException();
            promise.Reject(ex);

            var completed = 0;
            promise.Catch(e =>
            {
                Assert.AreEqual(ex, e);
                ++completed;
            });

            Assert.AreEqual(1, completed);
        }
開發者ID:rob-blackbourn,項目名稱:JetBlack.Promises,代碼行數:16,代碼來源:PromiseFixture.cs

示例6: CanRejectPromiseAndTriggerMultipleErrorHandlersInOrder

        public void CanRejectPromiseAndTriggerMultipleErrorHandlersInOrder()
        {
            var promise = new Promise<int>();

            var ex = new ApplicationException();
            var completed = 0;

            promise.Catch(e =>
            {
                Assert.AreEqual(ex, e);
                Assert.AreEqual(1, ++completed);
            });
            promise.Catch(e =>
            {
                Assert.AreEqual(ex, e);
                Assert.AreEqual(2, ++completed);
            });

            promise.Reject(ex);

            Assert.AreEqual(2, completed);
        }
開發者ID:rob-blackbourn,項目名稱:JetBlack.Promises,代碼行數:22,代碼來源:PromiseFixture.cs

示例7: can_reject_promise_and_trigger_error_handler

        public void can_reject_promise_and_trigger_error_handler()
        {
            var promise = new Promise();

            var ex = new ApplicationException();
            var completed = 0;
            promise.Catch(e =>
            {
                Assert.Equal(ex, e);
                ++completed;
            });

            promise.Reject(ex);

            Assert.Equal(1, completed);
        }
開發者ID:Renanse,項目名稱:C-Sharp-Promise,代碼行數:16,代碼來源:Promise_NonGeneric_Tests.cs

示例8: exception_thrown_during_resolver_rejects_proimse

        public void exception_thrown_during_resolver_rejects_proimse()
        {
            var ex = new Exception();
            var promise = new Promise((resolve, reject) =>
            {
                throw ex;
            });

            var completed = 0;
            promise.Catch(e =>
            {
                Assert.Equal(ex, e);
                ++completed;
            });

            Assert.Equal(1, completed);
        }
開發者ID:Renanse,項目名稱:C-Sharp-Promise,代碼行數:17,代碼來源:Promise_NonGeneric_Tests.cs

示例9: error_handler_is_not_invoked_for_resolved_promised

        public void error_handler_is_not_invoked_for_resolved_promised()
        {
            var promise = new Promise();

            promise.Catch(e =>
            {
                throw new ApplicationException("This shouldn't happen");
            });

            promise.Resolve();
        }
開發者ID:Renanse,項目名稱:C-Sharp-Promise,代碼行數:11,代碼來源:Promise_NonGeneric_Tests.cs

示例10: can_reject_promise_via_reject_function

        public void can_reject_promise_via_reject_function()
        {
            var ex = new Exception();
            var promise = new Promise((resolve, reject) =>
            {
                reject(ex);
            });

            var completed = 0;
            promise.Catch(e =>
            {
                Assert.Equal(ex, e);
                ++completed;
            });

            Assert.Equal(1, completed);
        }
開發者ID:Renanse,項目名稱:C-Sharp-Promise,代碼行數:17,代碼來源:Promise_NonGeneric_Tests.cs

示例11: Exception

            public void _If_onFulfilled_is_not_a_function_and_promise1_is_fulfilled_promise2_must_be_fulfilled_with_the_same_value_as_promise1()
            {
                var promise1 = new Promise<object>();

                var promise2 = promise1.Catch(_ => 
                {
                    throw new Exception("There shouldn't be an error");
                });

                var promisedValue = new object();
                var promise2ThenHandler = 0;

                promise2.Then(v =>
                {
                    Assert.Equal(promisedValue, v);
                    ++promise2ThenHandler;
                });

                promise1.Resolve(promisedValue);

                Assert.Equal(1, promise2ThenHandler);
            }
開發者ID:avenema,項目名稱:C-Sharp-Promise,代碼行數:22,代碼來源:2.2.cs

示例12: _when_promise1_is_rejected

                public void _when_promise1_is_rejected()
                {
                    var promise1 = new Promise<object>();

                    var e = new Exception();
                    var promise2 = 
                        promise1.Catch(_ =>
                        {
                            throw e;
                        });

                    promise1.Catch(_ =>
                    {
                        throw new Exception("This shouldn't happen!");
                    });

                    var errorHandledForPromise2 = 0;
                    promise2.Catch(ex =>
                    {
                        Assert.Equal(e, ex);

                        ++errorHandledForPromise2;
                    });

                    promise1.Reject(new Exception());

                    Assert.Equal(1, errorHandledForPromise2);
                }
開發者ID:avenema,項目名稱:C-Sharp-Promise,代碼行數:28,代碼來源:2.2.cs

示例13: _when_promise1_is_resolved_2

                public void _when_promise1_is_resolved_2()
                {
                    var promise1 = new Promise<object>();

                    var e = new Exception();
                    Action<object> thenHandler = _ =>
                    {
                        throw e;
                    };

                    var promise2 = 
                        promise1.Then(thenHandler);

                    promise1.Catch(_ =>
                    {
                        throw new Exception("This shouldn't happen!");
                    });

                    var errorHandledForPromise2 = 0;
                    promise2.Catch(ex =>
                    {
                        Assert.Equal(e, ex);

                        ++errorHandledForPromise2;
                    });

                    promise1.Resolve(new object());

                    Assert.Equal(1, errorHandledForPromise2);
                }
開發者ID:avenema,項目名稱:C-Sharp-Promise,代碼行數:30,代碼來源:2.2.cs

示例14: _when_promise_is_rejected_all_respective_onRejected_callbacks_must_execute_in_the_order_of_their_originating_calls_to_then

            public void _when_promise_is_rejected_all_respective_onRejected_callbacks_must_execute_in_the_order_of_their_originating_calls_to_then()
            {
                var promise = new Promise<object>();

                var order = 0;

                promise.Catch(_ =>
                {
                    Assert.Equal(1, ++order);
                });
                promise.Catch(_ =>
                {
                    Assert.Equal(2, ++order);
                });
                promise.Catch(_ =>
                {
                    Assert.Equal(3, ++order);
                });

                promise.Reject(new Exception());

                Assert.Equal(3, order);
            }
開發者ID:avenema,項目名稱:C-Sharp-Promise,代碼行數:23,代碼來源:2.2.cs

示例15: _must_have_a_reason_which_must_not_change

            public void _must_have_a_reason_which_must_not_change()
            {
                var rejectedPromise = new Promise<object>();
                var reason = new Exception();
                var handled = 0;

                rejectedPromise.Catch(e =>
                {
                    Assert.Equal(reason, e);
                    ++handled;
                });

                rejectedPromise.Reject(reason);

                Assert.Throws<ApplicationException>(() => rejectedPromise.Reject(new Exception()));

                Assert.Equal(1, handled);
            }
開發者ID:avenema,項目名稱:C-Sharp-Promise,代碼行數:18,代碼來源:2.1.cs


注:本文中的Promise.Catch方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。