Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there way to throw an Exception that occurred inside the Statemachine to the outside? #1055

Closed
KimDoubleB opened this issue Jun 16, 2022 · 2 comments
Labels
status/need-triage Team needs to triage and take a first look

Comments

@KimDoubleB
Copy link

Hi. I recently got to know spring-statemachine, and I'm learning to use it for a company project.

But there's a problem. There are cases where the logic of guard and action that I wrote generates an exception, and I want to process this exception outside of the state machine. But spring-statemachine handles all these exceptions internally.

  • In the case of guard, the guard just returns false when an exception occurs.
  • In the case of action, no transition occurs when an exception occurs.

Is there an option to throw an internal exception to the outside?

@github-actions github-actions bot added the status/need-triage Team needs to triage and take a first look label Jun 16, 2022
@KimDoubleB KimDoubleB changed the title Is there any way to throw an exception that occurred inside the State Machine to the outside? Is there way to throw an Exception that occurred inside the Statemachine to the outside? Jun 16, 2022
@mehmetsalgar
Copy link

State Machines runs with some principle called 'Run to Completion' as defined in this links 1 2, which in short means, when a state machine receives an Event it should start from a State and reach a State.

Now if an Action or Guard cause an exception and interrupts the Event processing and prevents State Machine reaches a State, this would be an undefined behaviour and unacceptable for State Machines.

For this reason, State Machines would not let exceptions escape outside of execution loop.

If there is chance an exception can occur in Guard/Action, it is developers responsibility to deal with it, by writing necessary code for it.

In Spring State Machine there is Event Listener which will trigger it when an Exception occurs, to notify the external client, but that will not stop the execution of the State Machine.

@KimDoubleB
Copy link
Author

@mehmetsalgar
Thank you for your kind explanation. I understood everything through your explanation.
Also, looking at the links you attached, it seems that there are many concepts that I get to know. It's getting more interesting.
I'll have to see if I can implement the logic I want using Event Listener.
Thank you very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/need-triage Team needs to triage and take a first look
Projects
None yet
Development

No branches or pull requests

2 participants