Glossary · Automation software engineering and architecture
Exception handling
German: Ausnahmebehandlung
In programming, exception handling is the mechanism and practice of catching exceptions raised during program execution and responding to them in a defined way, for example by cleaning up resources, logging, retrying, falling back or passing the error on.
- Software engineering
In one sentence
Exception handling catches runtime exceptions and responds in a defined way, such as cleaning up, logging, retrying or passing them on.
Example
The recipe service catches a file access exception, logs the path and error, keeps the last valid recipe loaded and reports a warning to the HMI.
How it applies
- Engineering: Catch exceptions where the program can actually do something meaningful about them. Catching everything and ignoring it hides defects; letting everything propagate to the top can stop critical functions unnecessarily.
- Real-time and embedded: Exception mechanisms can have unpredictable timing and memory use, so some embedded coding standards restrict or forbid them. PLC runtimes provide their own mechanisms, such as error tasks or try-catch extensions in some implementations.
- Documentation: Developer documentation should describe the project's exception strategy: which layers catch which exceptions and how they are reported. Service documentation should explain the resulting messages and what to do.
Exception handling vs. error handling
Error handling is the general practice of dealing with errors by any means, including status codes and checks. Exception handling is one specific mechanism within it. See also Fail-fast behavior, a design principle that often guides where exceptions are raised.