MessageProcessingSequence implements IMessageProcessingSequence, IDumpable { @Override public void catchException(final Throwable exception, final IObject context) throws NoExceptionHandleChainException, NestedChainStackOverflowException, ChangeValueException, InvalidArgumentException, ReadValueException { int causedLevel = stackIndex; int causedStep = stepStack[causedLevel]; int caughtLevel; int caughtStep; for (int i = stackIndex; i >= 0; --i) { IObject exceptionalChainAndEnv = chainStack[i].getExceptionalChainAndEnvironments(exception); if (null != exceptionalChainAndEnv) { this.afterExceptionAction = (IAction<IMessageProcessingSequence>) exceptionalChainAndEnv.getValue(this.afterExceptionActionFieldName); IReceiverChain exceptionalChain = (IReceiverChain) exceptionalChainAndEnv.getValue(this.chainFieldName); caughtLevel = i; caughtStep = stepStack[caughtLevel]; context.setValue(causeLevelFieldName, causedLevel); context.setValue(causeStepFieldName, causedStep); context.setValue(catchLevelFieldName, caughtLevel); context.setValue(catchStepFieldName, caughtStep); context.setValue(exceptionFieldName, exception); this.isException = true; callChain(exceptionalChain); return; } } throw new NoExceptionHandleChainException(exception, Arrays.copyOf(chainStack, stackIndex + 1), Arrays.copyOf(stepStack, stackIndex + 1)); } MessageProcessingSequence(final int stackDepth, final IReceiverChain mainChain); @Override void reset(); @Override boolean next(); @Override void goTo(final int level, final int step); @Override void end(); @Override int getCurrentLevel(); @Override int getStepAtLevel(final int level); @Override IMessageReceiver getCurrentReceiver(); @Override IObject getCurrentReceiverArguments(); @Override void callChain(final IReceiverChain chain); @Override void catchException(final Throwable exception, final IObject context); @Override IObject dump(final IObject options);  }
@Test(expected = NoExceptionHandleChainException.class) public void Should_throwWhenNoChainFoundForException() throws Exception { Throwable exception = mock(Throwable.class); when(mainChainMock.get(eq(0))).thenReturn(messageReceiverMocks[0]); IMessageProcessingSequence sequence = new MessageProcessingSequence(5, mainChainMock); sequence.catchException(exception, contextMock); }