Error Handling

From ScorecWiki

Revision as of 16:18, 3 August 2010; view current revision
←Older revision | Newer revision→
Jump to: navigation, search

The purpose of error handling in SCOREC software is to indicate that something is wrong inside execution, provide some useful information to user, or perform some specific operations. The error handling should not stop the execution of the program, so do not use functions like exit() or abort().

API Level

All API functions should return an integer representing the error. Additional API functions can be provided to decode these numbers into sentences describing the error. See, for example, the MPI_Error_string function used by the MPI library.

Internal

C++ Programs

Internal functions can return error in a variety of ways, and you should choose the way that makes the most sense for your function.

  • Exceptions are usually a good option. You can write your own, but also make use of the standard C++ exceptions.
  • Reserving a particular value of the output variable can be a good way to indicate that an error occurred. For example, a function that returns a pointer as a result might return NULL to indicate an error.
  • Use the technique used by the API functions of having the return value indicate the type of error (or success) and doing all output through function parameters.
  • Use perror to interpret errno for standard C errors.
Personal tools