Glossary · Automation software engineering and architecture
Exception (software)
Also known as: Exception, Runtime exception
German: Ausnahme
In programming, an exception is an event during program execution that disrupts the normal flow, such as division by zero, an invalid memory access or a failed operation, and that is signaled by transferring control to a handler instead of continuing with the next statement.
- Software engineering
In one sentence
An exception is a runtime event, such as division by zero or a failed operation, that transfers control to a handler.
Example
A division by zero in a scaling function raises an exception on the controller; without a handler, the runtime stops the PLC program and switches the controller to stop mode.
How it applies
- Engineering: Languages such as C++, C#, Java and Python use exceptions as a structured error mechanism. On controllers, processor exceptions or runtime errors, such as array index violations, may stop the program unless handled by a configured error task or handler.
- Operation: How a controller reacts to an unhandled exception, stopping, continuing or entering a defined state, must be known and appropriate for the machine. A stopped controller does not automatically mean a safe machine; safety functions are implemented separately.
- Documentation: Document the runtime's exception behavior and diagnostic messages in service documentation, and list the exceptions an API can raise in reference documentation.
Exception vs. error code
An error code is returned by a function and must be checked explicitly by the caller. An exception propagates automatically until a handler catches it. Exceptions make errors harder to ignore but can hide control flow; many embedded coding standards restrict their use for timing and predictability reasons.