home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tlx501.zip / EXCEPT.H < prev    next >
C/C++ Source or Header  |  1996-01-05  |  8KB  |  294 lines

  1. /****************************************************************************
  2.     $Id: except.h 501.0 1995/03/07 12:26:42 RON Exp $
  3.  
  4.     Copyright (c) 1991-95 Tarma Software Research. All rights reserved.
  5.  
  6.     Project:    Tarma Library for C++ V5.0
  7.     Author:    Ron van der Wal
  8.  
  9.     Declarations for exceptions.
  10.  
  11.     $Log: except.h $
  12.     Revision 501.0  1995/03/07 12:26:42  RON
  13.     Updated for TLX 5.01
  14.     Revision 1.10  1995/01/31 16:29:20  RON
  15.     Update for release 012
  16.     Added partial support for SunPro C++ compiler
  17.     Revision 1.9  1994/11/16  15:21:02  ron
  18.     Made TLXLocus constructors outline
  19.  
  20.     Revision 1.8  1994/10/05  18:21:26  ron
  21.     Renamed TLx...() functions to tl...()
  22.  
  23.     Revision 1.7  1994/09/28  14:26:51  ron
  24.     Removed Macintosh-style #include references
  25.  
  26.     Revision 1.6  1994/09/27  20:25:05  ron
  27.     Changed path separator from / to \
  28.  
  29.     Revision 1.5  1994/09/26  15:17:56  ron
  30.     Changed include file references
  31.  
  32.     Revision 1.4  1994/09/12  14:49:41  ron
  33.     Added PrintOn() and operator << overloading tot TLException
  34.  
  35.     Revision 1.3  1994/09/07  15:32:42  ron
  36.     Added TLXResize exception
  37.  
  38.     Revision 1.2  1994/09/06  13:58:22  ron
  39.     Added TLXAssert exception class
  40.  
  41.     Revision 1.1  1994/08/16  18:06:47  ron
  42.     Initial revision
  43.  
  44. ****************************************************************************/
  45.  
  46. #ifndef _TLX_EXCEPT_H
  47. #define _TLX_EXCEPT_H
  48.  
  49. #ifndef _TLX_TLX_H
  50. #include <tlx\501\tlx.h>
  51. #endif
  52.  
  53. class _RTLCLASS ios;
  54. class _RTLCLASS ostream;
  55.  
  56. /*---------------------------------------------------------------------------
  57.     TLXLocus -
  58.  
  59.     Class describing the locus of an exception or similar diagnostic.
  60. ---------------------------------------------------------------------------*/
  61.  
  62. struct _TLXCLASS TLXLocus
  63. {
  64.     const char *    mFile;
  65.     int            mLine;
  66.  
  67. public:
  68.     TLXLocus();
  69.     TLXLocus(const char *, int);
  70.     TLXLocus(const TLXLocus &);
  71. };
  72.  
  73. /*---------------------------------------------------------------------------
  74.     TLException -
  75.  
  76.     Base class for all exceptions thrown by TLX, apart from xalloc. Use
  77.     these exceptions as follows:
  78.  
  79.     THROW(TLException(LOCUS, ...))
  80. ---------------------------------------------------------------------------*/
  81.  
  82. class _TLXCLASS TLException
  83. {
  84.     TLXLocus        mLocus;
  85.  
  86. public:
  87.     // Static storage for the construction of exception messages. Can be
  88.     // used by only one exception at a time.
  89.  
  90.     static const size_t    sBufferSize;
  91.     static char        sBuffer[];
  92.  
  93. public:
  94.     TLException(const TLXLocus &);
  95.     virtual ~TLException();
  96.  
  97.     // All exceptions must be able to describe themselves
  98.  
  99.     virtual const char *Description() const;
  100.     const TLXLocus &    Locus() const { return mLocus; }
  101.  
  102.     // Output functions:
  103.     //
  104.     // - PrintOn() describes the exception on the given stream;
  105.     // - Report() describes the exception on the diagnostic output;
  106.     // - operator << is also overloaded.
  107.  
  108.     void        Report() const;
  109.     virtual ostream &    PrintOn(ostream &) const;
  110.     friend ostream & _TLXFUNC operator <<(ostream &, const TLException &);
  111. };
  112.  
  113. /*---------------------------------------------------------------------------
  114.     TLXAssert -
  115.  
  116.     Exception class for assertion failures. Use it as follows:
  117.  
  118.     THROW(TLXAssert(TLXLocus(file, line)))
  119. ---------------------------------------------------------------------------*/
  120.  
  121. class _TLXCLASS TLXAssert: public TLException
  122. {
  123. public:
  124.     TLXAssert(const TLXLocus &);
  125.     virtual const char *Description() const;
  126. };
  127.  
  128. /*---------------------------------------------------------------------------
  129.     TLXNullPtr -
  130.  
  131.     Exception class for NULL pointer exceptions. Use it as follows:
  132.  
  133.     THROW(TLXNullPtr(LOCUS))
  134. ---------------------------------------------------------------------------*/
  135.  
  136. class _TLXCLASS TLXNullPtr: public TLException
  137. {
  138. public:
  139.     TLXNullPtr(const TLXLocus &);
  140.     virtual const char *Description() const;
  141. };
  142.  
  143. /*---------------------------------------------------------------------------
  144.     TLXIndex -
  145.  
  146.     Exception class for out-of-range indices. Use it as follows:
  147.  
  148.     THROW(TLXIndex(LOCUS, index))
  149. ---------------------------------------------------------------------------*/
  150.  
  151. class _TLXCLASS TLXIndex: public TLException
  152. {
  153.     index_t        mIndex;
  154.  
  155. public:
  156.     TLXIndex(const TLXLocus &, index_t);
  157.     virtual const char *Description() const;
  158. };
  159.  
  160. /*---------------------------------------------------------------------------
  161.     TLXNotFound -
  162.  
  163.     Exception class for 'element not found' exceptions. Use it as follows:
  164.  
  165.     THROW(TLXNotFound(LOCUS))
  166. ---------------------------------------------------------------------------*/
  167.  
  168. class _TLXCLASS TLXNotFound: public TLException
  169. {
  170. public:
  171.     TLXNotFound(const TLXLocus &);
  172.     virtual const char *Description() const;
  173. };
  174.  
  175. /*---------------------------------------------------------------------------
  176.     TLXEmpty -
  177.  
  178.     Exception class for 'collection empty' exceptions. Use it as follows:
  179.  
  180.     THROW(TLXEmpty(LOCUS))
  181. ---------------------------------------------------------------------------*/
  182.  
  183. class _TLXCLASS TLXEmpty: public TLException
  184. {
  185. public:
  186.     TLXEmpty(const TLXLocus &);
  187.     virtual const char *Description() const;
  188. };
  189.  
  190. /*---------------------------------------------------------------------------
  191.     TLXFull -
  192.  
  193.     Exception class for 'collection full' exceptions. Use it as follows:
  194.  
  195.     THROW(TLXFull(LOCUS))
  196. ---------------------------------------------------------------------------*/
  197.  
  198. class _TLXCLASS TLXFull: public TLException
  199. {
  200. public:
  201.     TLXFull(const TLXLocus &);
  202.     virtual const char *Description() const;
  203. };
  204.  
  205. /*---------------------------------------------------------------------------
  206.     TLXAlloc -
  207.  
  208.     Exception class for memory allocations exceptions. Use it as follows:
  209.  
  210.     THROW(TLXAlloc(LOCUS, size))
  211. ---------------------------------------------------------------------------*/
  212.  
  213. class _TLXCLASS TLXAlloc: public TLException
  214. {
  215.     size_t        mSize;
  216.  
  217. public:
  218.     TLXAlloc(const TLXLocus &, size_t);
  219.     virtual const char *Description() const;
  220. };
  221.  
  222. /*---------------------------------------------------------------------------
  223.     TLXResize -
  224.  
  225.     Exception class for invalid resize exceptions. Use it as follows:
  226.  
  227.     THROW(TLXResize(LOCUS, newsize, minsize))
  228. ---------------------------------------------------------------------------*/
  229.  
  230. class _TLXCLASS TLXResize: public TLException
  231. {
  232.     size_t        mNewSize;
  233.     size_t        mMinSize;
  234.  
  235. public:
  236.     TLXResize(const TLXLocus &, size_t, size_t);
  237.     virtual const char *Description() const;
  238. };
  239.  
  240. /*---------------------------------------------------------------------------
  241.     TLXStdio -
  242.  
  243.     Exception class for stdio errors. Use it as follows:
  244.  
  245.     THROW(TLXStdio(LOCUS, filename))
  246. ---------------------------------------------------------------------------*/
  247.  
  248. class _TLXCLASS TLXStdio: public TLException
  249. {
  250.     int            mErrNo;
  251.     const char *    mFileName;
  252.  
  253. public:
  254.     TLXStdio(const TLXLocus &, const char *);
  255.     virtual const char *Description() const;
  256. };
  257.  
  258. /*---------------------------------------------------------------------------
  259.     TLXIos -
  260.  
  261.     Exception class for iostream errors. Use it as follows:
  262.  
  263.     THROW(TLXIos(LOCUS, ios-ref))
  264. ---------------------------------------------------------------------------*/
  265.  
  266. class _TLXCLASS TLXIos: public TLException
  267. {
  268.     int            mErrState;
  269.  
  270. public:
  271.     TLXIos(const TLXLocus &, const ios &);
  272.     virtual const char *Description() const;
  273. };
  274.  
  275. /*---------------------------------------------------------------------------
  276.     Helper functions and macros for exception handling.
  277. ---------------------------------------------------------------------------*/
  278.  
  279. #define    LOCUS        TLXLocus(__FILE__, __LINE__)
  280. void _TLXFUNC         _tlThrow(const TLException &);
  281.  
  282. /*---------------------------------------------------------------------------
  283.     Macros to fake exception handling for those compilers that don't yet
  284.     implement them.
  285. ---------------------------------------------------------------------------*/
  286.  
  287. #ifdef _NOEXCEPT
  288.     #define THROW(x)    _tlThrow(x)
  289. #else
  290.     #define THROW(x)    throw x
  291. #endif
  292.  
  293. #endif    // _TLX_EXCEPT_H
  294.