15.2 User-Defined Error Handling

Team-Fly

15.2 User-Defined Error Handling

As a rule, it is necessary to adapt error handling to particular requirements. The LINT class offers support in this regard in that the LINT error function panic() can be replaced by user-defined functions. Additionally, the following function is called, which takes as argument a pointer to a function:

   void   LINT::Set_LINT_Error_Handler (void (*Error_Handler)         (LINT_ERRORS, const char* const, const int, const int))   {     LINT_User_Error_Handler = Error_Handler;   } 

The variable LINT_User_Error_Handler is defined and initialized in flintpp.cpp as

   static void (*LINT_User_Error_Handler)          (LINT_ERRORS, const char*, const int, const int) = NULL; 

If this pointer has a value other than NULL, then the specified function is called instead of panic(), and it contains the same information as panic() would have. With respect to the implementation of a user-defined error-handling routine one has a great deal of freedom. But one must realize that the errors reported by the class LINT usually signal program errors, which are irreparable at run time. It would make no sense to return to the program segment in which such an error has occurred, and in general, in such cases the only reasonable course of action is to terminate the program.

The return to the LINT error routine panic() is effected by a call to

   LINT::Set_LINT_Error_Handler(NULL); 

The following example demonstrates the integration of a user-defined function for error handling:

 #include "flintpp.h"  void my_error_handler (LINT_ERRORS err, const char* str,                                    const int arg, const int line) {   //... Code } main() {   // activation of the user-defined error handler:   LINT::Set_LINT_Error_Handler (my_error_handler);   // ... Code   // reactivate the LINT error handler:   LINT::Set_LINT_Error_Handler (NULL);   // ... Code } 


Team-Fly


Cryptography in C and C++
Cryptography in C and C++
ISBN: 189311595X
EAN: 2147483647
Year: 2001
Pages: 127

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net