title: Error handling in embedded systems
body: <p>I'm thinking about error handling in embedded systems, specifically in C++, and I wanted to get some input on what I understand to be the different use cases for exceptions, return codes and asserts.</p>
  
  <p>Let's say we have a system that analyzes a signal it gets from a sensor and does some calculations on the results. If the signal is flat, we are outside the range of operation and we cannot perform the algorithms.</p>
  
  <p>Return codes: A flat signal is expected and is not an exceptional condition, a return code like FLAT_SIGNAL to let the higher level code know not to run the algorithms and to let the user know that we are out of range is sufficient. This is part of the normal program flow.</p>
  
  <p>Exceptions: If the sensor gets disconnected, or if the signal shows signs of other abnormal external conditions, throw an exception. </p>
  
  <p>Asserts: Use asserts to check the state of a class and/or on function parameters to look for programming errors or bugs. Should not be included in release code.</p>
  
  <p>EDIT: Adding a few specific questions.</p>
  
  <p>Is it OK to mix exceptions and return codes? Should asserts be turned off in release code? Does exceptions sound like overkill in the situation I described? </p>