Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

error.H

Go to the documentation of this file.
00001 #ifndef ERROR_H_IS_INCLUDED
00002 #define ERROR_H_IS_INCLUDED
00003 
00004 #include "platform.H"
00005 #include "iostream.H"
00006 
00007 
00008 // Warning Level
00009 //
00010 // Variable JOT_WARNING_LEVEL is querried before printing messages.
00011 // Only message with ERR_LEV <= JOT_WARNING_LEVEL are printed.
00012 // JOT_WARNING_LEVEL defaults to ERR_LEV_WARN (2)
00013 
00014 //
00015 // ERR_LEV_ERROR - (1) - Fatal errors (e.g. file not found, failed calculation, etc.)
00016 // ERR_LEV_WARN  - (2) - Non-fatal/recovered errors (e.g. tossed out bad gesture, data, etc.)
00017 // ERR_LEV_INFO  - (3) - Something informational (e.g. dimensions, bitplanes of loaded image)
00018 // ERR_LEV_SPAM  - (4) - Gratuitious information (e.g. "Class::Class() - Constructed!")
00019 
00020 #define ERR_LEV_ERROR    0x01
00021 #define ERR_LEV_WARN     0x02
00022 #define ERR_LEV_INFO     0x03
00023 #define ERR_LEV_SPAM     0x04
00024 
00025 #define ERR_LEV_MASK     0x0F
00026 
00027 // ERRNO String - Appends errno string to error message
00028 //
00029 #define ERR_INCL_ERRNO   0x10
00030 
00031 // Internal method -- don't call this one...
00032 void err_(int flags, const char *fmt, va_list ap);
00033 
00034 // Print error message:
00035 //
00036 // flags = ERR_INCL_ERRNO | one of ERR_LEV_* 
00037 //
00038 // E.g.: the following always prints:
00039 //    err_mesg(ERR_LEV_ERROR, ...);
00040 // but this only prints when JOT_WARNING_LEVEL == ERR_LEV_SPAM:
00041 //    err_mesg(ERR_LEV_SPAM, ...);
00042 inline void
00043 err_mesg(int flags, const char *fmt, ...)
00044 {
00045    va_list ap;
00046    va_start(ap, fmt);
00047    err_(flags, fmt, ap);
00048    va_end(ap);
00049 }
00050 
00051 // Conditionally print error message:
00052 //
00053 // doit = only print message if doit=true
00054 // flags = ERR_INCL_ERRNO | one of ERR_LEV_* 
00055 inline void
00056 err_mesg_cond(bool doit, int flags, const char *fmt, ...)
00057 {
00058    va_list ap;
00059    va_start(ap, fmt);
00060    if (doit) err_(flags, fmt, ap);
00061    va_end(ap);
00062 }
00063 
00064 // convenience form of err_mesg: always prints
00065 inline void
00066 err_msg(const char *fmt, ...)
00067 {
00068    va_list ap;
00069    va_start(ap, fmt);
00070    err_(ERR_LEV_ERROR, fmt, ap);
00071    va_end(ap);
00072 }
00073 
00074 // err_ret: print message about a system error,
00075 //          and return.
00076 inline void
00077 err_ret(const char *fmt, ...)
00078 {
00079    va_list ap;
00080    va_start(ap, fmt);
00081    err_(ERR_INCL_ERRNO | ERR_LEV_ERROR, fmt, ap);
00082    va_end(ap);
00083 }
00084 
00085 // err_sys: like err_ret, but also exits the program.
00086 inline void
00087 err_sys(const char *fmt, ...)
00088 {
00089    va_list ap;
00090    va_start(ap, fmt);
00091    err_(ERR_INCL_ERRNO | ERR_LEV_ERROR, fmt, ap);
00092    va_end(ap);
00093    exit(1);
00094 }
00095 
00096 // err_adv: (error advisory):
00097 //
00098 //   convenience method used in debugging.
00099 //   instead of:
00100 //      if (print_errs)
00101 //         err_msg("problem...");
00102 //   use:
00103 //      err_adv(print_errs, "problem...");
00104 inline void
00105 err_adv(bool doit, const char *fmt, ...)
00106 {
00107    if (!doit) return;
00108 
00109    va_list ap;
00110    va_start(ap, fmt);
00111    err_(ERR_LEV_ERROR, fmt, ap);
00112    va_end(ap);
00113 }
00114 
00115 #endif // ERROR_H_IS_INCLUDED
00116 
00117 /* end of file error.H */

Generated on Mon Sep 18 11:39:29 2006 for jot by  doxygen 1.4.4