home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / vc98 / mfc / src / arcex.cpp < prev    next >
C/C++ Source or Header  |  1998-06-16  |  3KB  |  104 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1998 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10.  
  11. #include "stdafx.h"
  12.  
  13. #ifdef AFX_CORE2_SEG
  14. #pragma code_seg(AFX_CORE2_SEG)
  15. #endif
  16.  
  17. #ifdef _DEBUG
  18. #undef THIS_FILE
  19. static char THIS_FILE[] = __FILE__;
  20. #endif
  21.  
  22. #define new DEBUG_NEW
  23.  
  24. #ifdef _DEBUG
  25. // character strings to use for dumping CArchiveException
  26. static const LPCSTR rgszCArchiveExceptionCause[] =
  27. {
  28.     "none",
  29.     "generic",
  30.     "readOnly",
  31.     "endOfFile",
  32.     "writeOnly",
  33.     "badIndex",
  34.     "badClass",
  35.     "badSchema",
  36. };
  37. static const char szUnknown[] = "unknown";
  38. #endif
  39.  
  40. BOOL CArchiveException::GetErrorMessage(LPTSTR lpszError, UINT nMaxError,
  41.     PUINT pnHelpContext)
  42. {
  43.     ASSERT(lpszError != NULL && AfxIsValidString(lpszError, nMaxError));
  44.  
  45.     if (pnHelpContext != NULL)
  46.         *pnHelpContext = m_cause + AFX_IDP_ARCH_NONE;
  47.  
  48.     // we can use CString here; archive errors aren't caused
  49.     // by being out of memory.
  50.  
  51.     CString strMessage;
  52.     CString strFileName = m_strFileName;
  53.     if (strFileName.IsEmpty())
  54.         strFileName.LoadString(AFX_IDS_UNNAMED_FILE);
  55.     AfxFormatString1(strMessage,
  56.         m_cause + AFX_IDP_ARCH_NONE, strFileName);
  57.     lstrcpyn(lpszError, strMessage, nMaxError);
  58.  
  59.     return TRUE;
  60. }
  61.  
  62.  
  63. /////////////////////////////////////////////////////////////////////////////
  64. // CArchiveException
  65.  
  66. #ifdef _DEBUG
  67. void CArchiveException::Dump(CDumpContext& dc) const
  68. {
  69.     CObject::Dump(dc);
  70.  
  71.     dc << " m_cause = ";
  72.     if (m_cause >= 0 && m_cause < _countof(rgszCArchiveExceptionCause))
  73.         dc << rgszCArchiveExceptionCause[m_cause];
  74.     else
  75.         dc << szUnknown;
  76.  
  77.     dc << "\n";
  78. }
  79. #endif //_DEBUG
  80.  
  81. void AFXAPI AfxThrowArchiveException(int cause,
  82.     LPCTSTR lpszArchiveName /* = NULL */)
  83. {
  84. #ifdef _DEBUG
  85.     LPCSTR lpsz;
  86.     if (cause >= 0 && cause < _countof(rgszCArchiveExceptionCause))
  87.         lpsz = rgszCArchiveExceptionCause[cause];
  88.     else
  89.         lpsz = szUnknown;
  90.     TRACE1("CArchive exception: %hs.\n", lpsz);
  91.  
  92. #endif //_DEBUG
  93.  
  94.     THROW(new CArchiveException(cause, lpszArchiveName));
  95. }
  96.  
  97. #ifdef AFX_INIT_SEG
  98. #pragma code_seg(AFX_INIT_SEG)
  99. #endif
  100.  
  101. IMPLEMENT_DYNAMIC(CArchiveException, CException)
  102.  
  103. /////////////////////////////////////////////////////////////////////////////
  104.