
I'm attempting to use StateChart to model a simple socket protocol and I'm having difficulty understanding how to handle protocol errors. I've read the sections on Error handling and two phase exit without gaining much insight. Those sections seem to be concerned with user-written code that cannot complete and thus must throw an exception. The type of error I'm currently concerned with is an unexpected event. For example, in this simple protocol we must first receive a hello before being ready to handle requests. A request returns data and must be followed by a commit, which completes the transaction and returns us to the ready state. (start state) (hello event) -> (ready state) (ready state) (get event) -> (data delivered) (data delivered) (commit event) -> (ready state) My problem is this: how do I detect and recover when I'm in the (data delivered) state and the next event is not a (commit event)? The only thing I can see is that the unconsumed_event() function is called with the unexpected event object. What I'd like to do in this function is: 1. Abort my transaction and force the state machine back to the Ready state. I'm not sure how to do this. 2. Reprocess the unexpected event if it is a hello or get, discard it otherwise. I'm not sure how to do this, either. At a more abstract level, it seems that unconsumed_event() is the only way to deal with an unexpected event and to try to reset the state machine. Is this true? Thanks, -- Robert