home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / tlx501.zip / SRC / EXCEPT.CPP < prev    next >
C/C++ Source or Header  |  1996-07-08  |  5KB  |  135 lines

  1. /****************************************************************************
  2.     $Id: except.cpp 501.0 1995/03/07 12:26:14 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.     Implementation of exception handling functions.
  10.  
  11.     $Log: except.cpp $
  12.     Revision 501.0  1995/03/07 12:26:14  RON
  13.     Updated for TLX 5.01
  14.     Revision 1.12  1995/01/31 16:30:14  RON
  15.     Update for release 012
  16.     Added partial support for SunPro C++ compiler
  17.     Revision 1.11  1995/01/06  15:57:48  ron
  18.     Corrected Revision keyword
  19.  
  20.     Revision 1.10  1995/01/05  15:24:18  ron
  21.     Changed exception reporting format slightly
  22.  
  23.     Revision 1.9  1994/11/16  15:39:26  ron
  24.     Moved individual exception classes to separate files
  25.     Added module info; rearranged #include directives
  26.  
  27.     Revision 1.8  1994/10/05  18:38:09  ron
  28.     Renamed TLx...() functions to tl...()
  29.  
  30.     Revision 1.7  1994/09/28  14:18:30  ron
  31.     Removed Macintosh-style #include references
  32.  
  33.     Revision 1.6  1994/09/27  20:22:26  ron
  34.     Changed path separator from / to \
  35.  
  36.     Revision 1.5  1994/09/26  15:42:52  ron
  37.     Changed include file references
  38.  
  39.     Revision 1.4  1994/09/12  14:54:44  ron
  40.     Implemented PrintOn() and operator << overloading for TLException
  41.  
  42.     Revision 1.3  1994/09/07  15:43:02  ron
  43.     Implemented class TLXResize
  44.  
  45.     Revision 1.2  1994/09/06  14:10:10  ron
  46.     Added TLXAssert and TLXIos exceptions
  47.  
  48.     Revision 1.1  1994/08/16  18:13:04  ron
  49.     Initial revision
  50.  
  51. ****************************************************************************/
  52.  
  53. #include <tlx\501\_build.h>
  54.  
  55. TLX_MODULE_INFO("$Revision: 501.0 $");
  56.  
  57. #include <iostream.h>
  58. #include <tlx\501\except.h>
  59.  
  60. /*-------------------------------------------------------------------------*/
  61.     void _TLXFUNC _tlThrow(const TLException &aX)
  62.  
  63. /*  Helper function to simulate an exception if there is no compiler support
  64.     for it. It displays a diagnostic that allows the user to choose whether
  65.     or not to continue.
  66. ---------------------------------------------------------------------------*/
  67. {
  68.     TLAssert::Diagnostic(TLAssert::dfError, aX.Locus().mFile, aX.Locus().mLine,
  69.                   "Exception: %s", aX.Description());
  70. }
  71.  
  72. /*---------------------------------------------------------------------------
  73.     Implementation of class TLException
  74. ---------------------------------------------------------------------------*/
  75.  
  76. const size_t     TLException::sBufferSize = 256;
  77. char            TLException::sBuffer[TLException::sBufferSize];
  78.  
  79. /*-------------------------------------------------------------------------*/
  80.     TLException::TLException(const TLXLocus &aLocus)
  81.  
  82. /*  Constructor, initializes locus member.
  83. ---------------------------------------------------------------------------*/
  84. : mLocus(aLocus)
  85. {
  86. }
  87.  
  88. /*-------------------------------------------------------------------------*/
  89.     TLException::~TLException()
  90.  
  91. /*  Destructor. Does nothing, but is declared virtual for derivation.
  92. ---------------------------------------------------------------------------*/
  93. {
  94. }
  95.  
  96. /*-------------------------------------------------------------------------*/
  97.     const char *TLException::Description() const
  98.  
  99. /*  Returns a pointer to a string describing the exception. The description
  100.     does *not* include the locus.
  101. ---------------------------------------------------------------------------*/
  102. {
  103.     return "TLX exception";
  104. }
  105.  
  106. /*-------------------------------------------------------------------------*/
  107.     ostream &TLException::PrintOn(ostream &os) const
  108.  
  109. /*  Prints a description of the exception on the given stream.
  110. ---------------------------------------------------------------------------*/
  111. {
  112.     return os << Description() << " (from: " << mLocus.mFile << " ["
  113.            << mLocus.mLine << "])";
  114. }
  115.  
  116. /*-------------------------------------------------------------------------*/
  117.     void TLException::Report() const
  118.  
  119. /*  Reports the exception (description + locus) with the aid of the
  120.     diagnostic output functions.
  121. ---------------------------------------------------------------------------*/
  122. {
  123.     _tlThrow(*this);
  124. }
  125.  
  126. /*-------------------------------------------------------------------------*/
  127.     ostream & _TLXFUNC operator <<(ostream &os, const TLException &x)
  128.  
  129. /*  Overloads the output operator for exceptions.
  130. ---------------------------------------------------------------------------*/
  131. {
  132.     return x.PrintOn(os);
  133. }
  134.  
  135.