A handler function type for dealing with errors during state handling in a finite state machine. The handler receives the state that caused the error and the thrown exception, and can optionally return a new state to continue the chain, or null to end the chain.