home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / krcls012.zip / KrClass / include / krtrace.hpp < prev    next >
C/C++ Source or Header  |  1997-02-22  |  3KB  |  109 lines

  1. // Kroni's Classes: objects for exception handling and tracing
  2. // (c) 1997 Wolfgang Kronberg
  3. // file: krtrace.hpp
  4.  
  5. // **********************************************************************************************************
  6. //
  7. // defines these classes:
  8. //
  9. //   KrTrace                 Analogous to ITrace, this class provides support for error reporting
  10. //
  11. // defines these macros:
  12. //
  13. //   KRTHROW (ex)            Like ITHROW, but also works with exceptions declared as temporaries
  14. //   KRNAMEDTHROW (ex,name)  Like KRTHROW, but sets the exception group name to "name"
  15. //
  16. // defines those global symbols for private use:
  17. //
  18. //   _KrException
  19. //   _KRSYSTHROW (ex)
  20. //
  21. // **********************************************************************************************************
  22.  
  23.  
  24. #ifndef __KRTRACE_HPP__
  25. #define __KRTRACE_HPP__
  26.  
  27.  
  28. #include <fstream.h>
  29.  
  30. #include <iexcbase.hpp>
  31. #include <ivbase.hpp>
  32. #include <istring.hpp>
  33.  
  34.  
  35. class _KrException : public IException
  36. {
  37.  
  38. public:
  39.  
  40.   _KrException (const IException & ex, const IString & aTypeName);
  41.                                                  // Standard Constructor
  42.  
  43.   virtual const char * name () const;
  44.   IException & setErrorCodeGroup (ErrorCodeGroup aErrorGroup);
  45.  
  46. private:
  47.  
  48.   IString typeName;
  49.   IString errorGroup;
  50.  
  51. };
  52.  
  53.  
  54. class KrTrace : public IBase
  55. {
  56.  
  57. public:
  58.  
  59.   typedef void (*vvf)();                         // Defines vvf as the type of a function void -> void
  60.  
  61.   enum traceTarget {stdout, stderr, file, queue, none};
  62.   enum userInfo {noMsg, simple, logFile, full};  // What kind of MessageBox should inform the user
  63.                                                  //   about any kind of unexpected exception?
  64.  
  65.   static void traceTo (traceTarget aTarget);     // To which destination should be traced?
  66.   static void traceTo (const IString & s);       // Trace to the file with this name
  67.   static void traceTo ();                        // Trace to progname.log
  68.   static void tellUser (userInfo aInfo);         // How detailed should the user be informed?
  69.  
  70.   static void _throw (
  71.     const IException & ex, const char* fileName, const char* functionName,
  72.     unsigned long lineNumber);
  73.  
  74.   static void _throw (
  75.     const IException & ex, const char* fileName, const char* functionName,
  76.     unsigned long lineNumber, const IString & group);
  77.  
  78.  
  79. private:
  80.  
  81.   KrTrace () {};                                 // Private default constructor, so that no objects
  82.                                                  //   of this class can be constructed
  83.  
  84.   static void _terminate ();                     // Replaces the "common" terminate() function
  85.  
  86.   static _KrException * lastException;
  87.   static vvf oldFunction;
  88.   static traceTarget target;
  89.   static userInfo info;
  90.   static IString fileName;
  91.   static ofstream * lFile;
  92.  
  93. };
  94.  
  95.  
  96. #define KRTHROW(exc)\
  97.           KrTrace::_throw (exc,__FILE__,__FUNCTION__,__LINE__)
  98.                                                  // Use this to simply throw an exception
  99.  
  100. #define KRNAMEDTHROW(exc,name)\
  101.           KrTrace::_throw (exc,__FILE__,__FUNCTION__,__LINE__,name)
  102.                                                  // Use this to throw exceptions of your own group
  103.  
  104. #define _KRSYSTHROW(exc)\
  105.           KRNAMEDTHROW (exc,"Kroni's Classes")   // Used to throw exceptions within Kroni's Classes
  106.  
  107. #endif
  108.  
  109.