Tutorial
Defining a new error
Adding an unobservable property for the door state.
In this tutorial, we want to preface error handling. We will define a custom error for a theoretical mechanical failure of the door. We define this error in the door_controller_base.py
file. Alternative the error can also be defined in it's own file, for example in case this error can happen in multiple features.
door_controller_base.py
class DoorMalfunctionError(sila.DefinedExecutionError):
"""
A hardware malfunction was detected, and the called door method cannot be completed.
Please manually check the device and refer to the device manual for reparation instructions.
"""
Code explanation
We create a class called DoorMalfunctionError
that inherits from sila.DefinedExecutionError
.
The docstring contains the information the user receives whenever this error is raised.The __init__.py
file is updated to include the DoorMalfunctionError
.
from .door_controller_base import DoorControllerBase, DoorMalfunctionError
__all__ = ["DoorControllerBase", "DoorMalfunctionError"]