public void handlers_that_wrap_exceptions_return_on_tryfire() { var bus = new CommandBus("local"); long gotCmd = 0; long gotResponse = 0; long gotAck = 0; long msgCount = 0; const string errText = @"I knew this would happen."; bus.Subscribe(new AdHocCommandHandler <TestCommands.TestCommand>( cmd => { Interlocked.Exchange(ref gotCmd, 1); throw new CommandException(errText, cmd); }, // ReSharper disable once RedundantArgumentDefaultValue wrapExceptions: true)); bus.Subscribe(new AdHocHandler <CommandResponse>( cmd => Interlocked.Exchange(ref gotResponse, 1))); bus.Subscribe(new AdHocHandler <AckCommand>( cmd => Interlocked.Exchange(ref gotAck, 1))); bus.Subscribe(new AdHocHandler <Message>( cmd => Interlocked.Increment(ref msgCount))); CommandResponse response; var command = new TestCommands.TestCommand(Guid.NewGuid(), null); var passed = bus.TryFire(command, out response); Assert.False(passed, "Expected false return"); Assert.IsType(typeof(Fail), response); Assert.IsType(typeof(CommandException), ((Fail)response).Exception); Assert.True(string.Equals($"{command.GetType().Name}: {errText}", ((Fail)response).Exception.Message, StringComparison.Ordinal)); Assert.IsOrBecomesTrue(() => Interlocked.Read(ref msgCount) == 3, null, "Expected 3 Messages"); Assert.IsOrBecomesTrue(() => Interlocked.Read(ref gotAck) == 1, null, "Expected Ack"); Assert.IsOrBecomesTrue(() => Interlocked.Read(ref gotCmd) == 1, null, "Expected Command was handled"); Assert.IsOrBecomesTrue(() => Interlocked.Read(ref gotResponse) == 1, null, "Expected Response"); }