Embedded Software Colin Walls
Colin Walls has over thirty years experience in the electronics industry, largely dedicated to embedded software. A frequent presenter at conferences and seminars and author of numerous technical articles and two books on embedded software, Colin is an embedded software technologist with Mentor … More » Exception handling in C++November 18th, 2019 by Colin Walls
Various aspects of the C++ language concern embedded software engineers, and a particular one is exception handling … The Exception Handling System [EHS] in C++ has nothing to be with exceptions in the sense of being hardware interrupts. It is designed to handle exceptional situations that are detected by the software. The intention is to provide a controlled failure mode, where a smooth exit from some deeply nested function calls is required [without resorting to goto]. The use of EHS is quite straightforward. Code that needs EHS activated during its execution is enclosed in a try block. A throw statement is used to assert an exception, which is identified by means of a class. Processing of the exception is performed by some code in a catch block. There is normally one catch block for each type of exception that may be asserted. This seems quite neat and simple and does provide a way to write fairly readable code in which exception handling is needed. However, there are some key points that should make embedded developers wary:
Personally, I would shy away from using EHS, but, used with care, it may be beneficial to many designs. The overhead should be carefully measured. |