Search code examples
masstransitautomatonymous

Throw UnhandledEventException if the event is filtered


I've a scenario where a certain filter has to be matched before we can transition into a new state. So i've setup a filter, and registerd OnUnhandledEvent to throw exceptions if the event isn't handled. Unfortunately, it doesn't throw any errors. Automatonymous seems to mark this as handled because we are in the right state to handle the event.

Is there an option to manually throw an UnhandledException?

            During(
                this.ToBeReviewed,
                When(this.Approve, IsCreatedByOtherUserAccountId())
                    .TransitionTo(this.Approved)
                    .Then(AddUserAcceptedEvent));


            OnUnhandledEvent(x => x.Throw()); // Not working because the event is filtered above

Solution

  • You could throw the exception yourself. The state machine isn't going to throw if you're in a state that handles the event.

    .Then(_ => throw new UnhandledEventException);