Error Handling

SAF can be used either in an exception-catching programming paradigm or test the return code programming paradigm. SAF will either throw exceptions or return error codes depending on a library property (see saf_setProps_ErrorMode).

See *Environment* section where environment variables affecting error checking, etc. are discussed.

In addition, the client can control if and how error messages are reported and whether certain kinds of errors are detected. In every function, SAF does work to detect problematic conditions. However, the cost of this detection work is weighted relative to the real work of the function using a low, medium and high weighting scheme.

There are several macros available to use in an exception handling programming style rather than a test the return value style. The basic structure of an exception handling style is…

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
 SAF_TRY_BEGIN {      // begin an exception/catch block
     ...              // put your saf calls here
 } SAF_CATCH {        // begin the catch block
     // catch a particular error
     SAF_CATCH_ERR(SAF_WRITE_ERROR) {
         ...          // specific error handling here
     }
     SAF_CATCH_ALL {  // catch any error here
         ...          // generic error handling here
     }
 } SAF_TRY_END;       // end the exception/catch block