本文整理汇总了C#中ExceptionHandler.On方法的典型用法代码示例。如果您正苦于以下问题:C# ExceptionHandler.On方法的具体用法?C# ExceptionHandler.On怎么用?C# ExceptionHandler.On使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ExceptionHandler
的用法示例。
在下文中一共展示了ExceptionHandler.On方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: When_rethrows_if_no_handler
public void When_rethrows_if_no_handler()
{
var exceptions = new Dictionary<Type, Action>();
var exception = new ExceptionHandler(exceptions);
int invoke = 0;
Action action = () => invoke++;
Assert.Throws<NotImplementedException>(() => exception.On<AbandonedMutexException>(action).When(() => { throw new NotImplementedException(); }));
}
示例2: When_invokes_target
public void When_invokes_target()
{
var exceptions = new Dictionary<Type, Action>();
var exception = new ExceptionHandler(exceptions);
int invoke = 0;
Action action = () => Console.WriteLine("caught");
exception.On<Exception>(action).When(() => invoke++);
invoke.ShouldBe(1);
}
示例3: When_invokes_exception_handler_on_exception
public void When_invokes_exception_handler_on_exception()
{
var exceptions = new Dictionary<Type, Action>();
var exception = new ExceptionHandler(exceptions);
int invoke = 0;
Action action = () => invoke++;
exception.On<NotImplementedException>(action).When(() => { throw new NotImplementedException(); });
invoke.ShouldBe(1);
}
示例4: On_Exception_adds_exception_and_target_invocation
public void On_Exception_adds_exception_and_target_invocation()
{
var exceptions = new Dictionary<Type, Action>();
var exception = new ExceptionHandler(exceptions);
Action action = () => Console.WriteLine("caught");
exception.On<Exception>(action);
exceptions.ContainsKey(typeof(Exception));
exceptions.ContainsValue(action);
exceptions.Count.ShouldBe(1);
}