Error handling in hstio.c



next up previous
Next: IRAF initialization Up: A Descritpion of the Previous: Deleting keywords in

Error handling in hstio.c

I have built in some degree of flexibility into the error handling. The routines that return status information return 0 if successful and -1 for an error. You can access further error information via the functions:

                HSTIOError hstio_err();
                char *hstio_errmsg();

The first merely returns an enumerated code. The second returns a text string with the error message itself. These functions can be examined after any operation. ``hstio_err()'' will return 0 if there was no error.

In addition, you can install a global error handler. Suppose you have a function of the form:

                void detect_error() {
                        fprintf(stderr,"There was an ERROR!\n%s\n",
                                hstio_errmsg());
                        ... or whatever ...
                        ... decide what to do ...
                }

Then, you can install this function as a global error handler with the function:

                push_hstioerr(detect_error);

There is a stack of function pointers (limited to a nesting depth of 32, which is arbitrary). If there is a non-zero pointer on the stack, that function is automatically called when an error occurs. You are free to do anything in the error handling function: print a message, abort, or whatever. Execution continues after executing the error handling function.

Of course, there is also a pop function:

                pop_hstioerr();

So, you can manipulate the error handling stack as you see fit, e. g. by installing a new error handling function at the beginning of some complex procedure and popping it at the end. At any point, if you want to override the action of the global handler and give special handling after executing some function, you can merely push 0 onto the stack before executing the operation. That prevents the global error handler from being called. Of course, the pop function then restores the global error handler.



Sdas Group
Wed Aug 21 10:27:26 EDT 1996