Next: 3 Operating system specific Up: 2 The system Previous: 2.4 Calling conventions

# 2.5 Error handling

The section above already gave a brief introduction to MIDAS error handling, but this section will describe it in detail.

MIDAS uses a common method for handling errors throughout the system. All functions return an error code, and it is up to the caller to decide how to handle the error condition. Most functions simply pass the error code to their caller, but it is recommended that the function does as much clean-up as possible before doing so. In particular, all allocated memory should be deallocated and all open files closed.

When MIDAS is compiled in DEBUG mode, the error handling system has additional functionality. It will build up a list of all errors that occurred, with the name of the function that raised the error. When errors are then passed upwards in the function call stack, all functions are added to the list. Thus the error exit not only reports what error occurred, but also what function caused the error and where it was called.