home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / yacl-012.zip / base / error.h < prev    next >
C/C++ Source or Header  |  1995-04-08  |  2KB  |  82 lines

  1.  
  2. #ifndef _error_h_
  3. #define _error_h_
  4.  
  5.  
  6.  
  7.  
  8.  
  9. /*
  10.  *
  11.  *          Copyright (C) 1994, M. A. Sridhar
  12.  *  
  13.  *
  14.  *     This software is Copyright M. A. Sridhar, 1994. You are free
  15.  *     to copy, modify or distribute this software  as you see fit,
  16.  *     and to use  it  for  any  purpose, provided   this copyright
  17.  *     notice and the following   disclaimer are included  with all
  18.  *     copies.
  19.  *
  20.  *                        DISCLAIMER
  21.  *
  22.  *     The author makes no warranties, either expressed or implied,
  23.  *     with respect  to  this  software, its  quality, performance,
  24.  *     merchantability, or fitness for any particular purpose. This
  25.  *     software is distributed  AS IS.  The  user of this  software
  26.  *     assumes all risks  as to its quality  and performance. In no
  27.  *     event shall the author be liable for any direct, indirect or
  28.  *     consequential damages, even if the  author has been  advised
  29.  *     as to the possibility of such damages.
  30.  *
  31.  */
  32.  
  33.  
  34.  
  35.  
  36. #ifdef __GNUC__
  37. #pragma interface
  38. #endif
  39.  
  40. #include "base/defs.h"
  41.  
  42.  
  43. // This class is an encapsulation of a simple error-handling
  44. // mechanism. The Warning and Fatal methods accept parameters in the
  45. // same style as printf does; thus, for example, a user of this class
  46. // may say:
  47. // \par{\small \begin{verbatim}
  48. //          CL_Error::Warning ("Bad array bound %d limit %d", i, n);
  49. //\end{verbatim}
  50. // }\par
  51. // The Warning method formats the string, and then invokes the warning
  52. // handler with the formatted string. The default warning handler
  53. // simply prints out the message.
  54. //
  55. // The Fatal handler behaves similarly; it invokes the fatal-error
  56. // handler, and exits the program if the latter returns TRUE.
  57. //
  58. // The SetWarningHandler and SetFatalHandler methods can be used to
  59. // provide user-specific warning and fatal handlers instead of the
  60. // default ones. These methods return the previous values for their handlers.
  61.  
  62.  
  63. typedef bool (*CL_ErrorHandler) (const char* message);
  64.  
  65.  
  66. class CL_EXPORT CL_Error {
  67.  
  68. public:
  69.  
  70.     static void Warning (const char *fmt, ...);
  71.     // Issue a warning message, using the current warning handler.
  72.  
  73.     static void Fatal   (const char *fmt, ...);
  74.  
  75.     static CL_ErrorHandler SetWarningHandler    (CL_ErrorHandler handler);
  76.  
  77.     static CL_ErrorHandler SetFatalErrorHandler (CL_ErrorHandler handler);
  78.     
  79. };
  80.  
  81. #endif
  82.