当前位置: 首页>>代码示例>>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;未经允许,请勿转载。