home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ocl150a.zip / OCL / Source / OPMException.cpp < prev    next >
C/C++ Source or Header  |  1996-08-12  |  4KB  |  135 lines

  1. // OCL - OS/2 Class Library
  2. // (c) Cubus 1995
  3. // All Rights Reserved
  4. // OPMException.cpp
  5.  
  6.  
  7. /*
  8.  * Redistribution and use in source and binary forms, with or without
  9.  * modification, are permitted provided that the following conditions
  10.  * are met:
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  * 2. Neither the name Cubus nor the name Team OCL may be used to
  14.  *    endorse or promote products derived from this software
  15.  *    without specific prior written permission.
  16.  * 3. See OCL.INF for a detailed copyright notice.
  17.  *
  18.  *              THIS SOFTWARE IS PROVIDED ``AS IS'' AND
  19.  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21.  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  22.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  23.  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  24.  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  25.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  26.  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  27.  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  28.  * SUCH DAMAGE.
  29.  */
  30.  
  31. // $Header: W:/Projects/OCL/Source/rcs/OPMException.cpp 1.50 1996/08/11 23:49:25 B.STEIN Release $
  32.  
  33. #define __OCL_SOURCE__
  34.  
  35. #define OINCL_OSTRING
  36. #define OINCL_BASE
  37.  
  38. #include <ocl.hpp>
  39. #include <OPMException.hpp>
  40. #include <OMessage.hpp>
  41.  
  42.  
  43. OPMException::OPMException(const PSZ err,
  44.                            const ULONG retcode,
  45.                            const ULONG severity,
  46.                            const PSZ source,
  47.                            const ULONG line)
  48.   : OException(err, retcode, severity, source, line),
  49.     errRes(0)
  50.   {}
  51.  
  52.  
  53.  
  54. OPMException::OPMException(const ULONG errResource, 
  55.                            const ULONG retcode,     
  56.                            const ULONG severity,
  57.                            const HMODULE mod,
  58.                            const PSZ source,
  59.                            const ULONG line)        
  60.   : OException(NULL, retcode, severity, source, line),
  61.     exMsg(mod),
  62.     errRes(errResource)
  63.   {
  64.    if (errRes)
  65.     {
  66.      exMsg.loadString(errRes, 2*CCHMAXPATH, exMsg.message());
  67.      description << exMsg.message();
  68.     }
  69.   }
  70.  
  71.  
  72. OPMException::OPMException(const OPMException& ex)
  73.   : OException(ex.description, ex.rc, ex.state, ex.Source, ex.Line),
  74.     exMsg((HMODULE)ex.exMsg),
  75.     message(ex.message),
  76.     errRes(ex.errRes)
  77.   {
  78.    if (errRes) {
  79.      exMsg.loadString(errRes, 2*CCHMAXPATH, exMsg.message());
  80.      description << exMsg.message(); }
  81.   }
  82.  
  83.  
  84. OPMException::~OPMException()
  85.   {}
  86.  
  87.  
  88. PSZ OPMException::isOfType() const
  89.  return("OPMException"); 
  90. }
  91.  
  92.  
  93.  
  94.  
  95. void OPMException::viewError()
  96. {
  97.  OString   err;
  98.  PERRINFO  pErrInfoBlk;
  99.  PSZ       pszOffset;
  100.  CHAR      ErrBuffer[512];
  101.  
  102.  err <<  OMessage(190, OCL::MSGFILE);
  103.  err +   "\n";
  104.  err +   OMessage(191, OCL::MSGFILE, Source);
  105.  sprintf(ErrBuffer, "%d", Line);
  106.  err +   OMessage(192, OCL::MSGFILE, ErrBuffer);
  107.  err +   OMessage(193, OCL::MSGFILE, isOfType());
  108.  sprintf(ErrBuffer, "%d", rc);
  109.  err +   OMessage(194, OCL::MSGFILE, ErrBuffer);
  110.  sprintf(ErrBuffer, "%d", WinGetLastError(OApp::current().anchor()));
  111.  err +   OMessage(197, OCL::MSGFILE, ErrBuffer);
  112.  
  113.  strcpy(ErrBuffer, "");
  114.  
  115.  while((pErrInfoBlk = WinGetErrorInfo(OApp::current().anchor())) != (PERRINFO)NULL)
  116.   {
  117.    pszOffset = ((PSZ)pErrInfoBlk) + pErrInfoBlk->offaoffszMsg;
  118.    strcat(ErrBuffer, (((PSZ)pErrInfoBlk) + *((PSHORT)pszOffset)));
  119.    WinFreeErrorInfo(pErrInfoBlk);
  120.   }
  121.  
  122.  err +   OMessage(198, OCL::MSGFILE, ErrBuffer);
  123.  
  124.  if (!description) 
  125.   description << OMessage(190, OCL::MSGFILE);
  126.  
  127.  err +   OMessage(195, OCL::MSGFILE, "\n", description);
  128.  
  129.  exMsg.error("Note!", err);
  130. }
  131.  
  132.  
  133. // end of source
  134.