Reporting errors to the user
Sometimes, it’s required to stop processing during method execution because the user’s activity is invalid or an error condition has been satisfied. By displaying an informative error message, this tutorial demonstrates how to handle these situations.
The UserError
exception is commonly utilized to inform users about errors or exceptional situations. It is typically employed when the user’s input fails to meet the expected criteria or when a particular operation cannot be executed due to specific conditions.
Getting ready
This tutorial requires that you set up an instance with the my_hostel
add-on module installed, as per the instructions from before.
How to do it…
We will make a change to the change_state
method from the previous tutorial and display a helpful message when the user is trying to change the state that is not allowed by the is_allowed_transition
method. Perform the following steps to get started...