arcex.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. #include "stdafx.h"
  11. #ifdef AFX_CORE2_SEG
  12. #pragma code_seg(AFX_CORE2_SEG)
  13. #endif
  14. #ifdef _DEBUG
  15. #undef THIS_FILE
  16. static char THIS_FILE[] = __FILE__;
  17. #endif
  18. #define new DEBUG_NEW
  19. #ifdef _DEBUG
  20. // character strings to use for dumping CArchiveException
  21. static const LPCSTR rgszCArchiveExceptionCause[] =
  22. {
  23. "none",
  24. "generic",
  25. "readOnly",
  26. "endOfFile",
  27. "writeOnly",
  28. "badIndex",
  29. "badClass",
  30. "badSchema",
  31. };
  32. static const char szUnknown[] = "unknown";
  33. #endif
  34. BOOL CArchiveException::GetErrorMessage(LPTSTR lpszError, UINT nMaxError,
  35. PUINT pnHelpContext)
  36. {
  37. ASSERT(lpszError != NULL && AfxIsValidString(lpszError, nMaxError));
  38. if (pnHelpContext != NULL)
  39. *pnHelpContext = m_cause + AFX_IDP_ARCH_NONE;
  40. // we can use CString here; archive errors aren't caused
  41. // by being out of memory.
  42. CString strMessage;
  43. CString strFileName = m_strFileName;
  44. if (strFileName.IsEmpty())
  45. strFileName.LoadString(AFX_IDS_UNNAMED_FILE);
  46. AfxFormatString1(strMessage,
  47. m_cause + AFX_IDP_ARCH_NONE, strFileName);
  48. lstrcpyn(lpszError, strMessage, nMaxError);
  49. return TRUE;
  50. }
  51. /////////////////////////////////////////////////////////////////////////////
  52. // CArchiveException
  53. #ifdef _DEBUG
  54. void CArchiveException::Dump(CDumpContext& dc) const
  55. {
  56. CObject::Dump(dc);
  57. dc << " m_cause = ";
  58. if (m_cause >= 0 && m_cause < _countof(rgszCArchiveExceptionCause))
  59. dc << rgszCArchiveExceptionCause[m_cause];
  60. else
  61. dc << szUnknown;
  62. dc << "\n";
  63. }
  64. #endif //_DEBUG
  65. void AFXAPI AfxThrowArchiveException(int cause,
  66. LPCTSTR lpszArchiveName /* = NULL */)
  67. {
  68. #ifdef _DEBUG
  69. LPCSTR lpsz;
  70. if (cause >= 0 && cause < _countof(rgszCArchiveExceptionCause))
  71. lpsz = rgszCArchiveExceptionCause[cause];
  72. else
  73. lpsz = szUnknown;
  74. TRACE1("CArchive exception: %hs.\n", lpsz);
  75. #endif //_DEBUG
  76. THROW(new CArchiveException(cause, lpszArchiveName));
  77. }
  78. #ifdef AFX_INIT_SEG
  79. #pragma code_seg(AFX_INIT_SEG)
  80. #endif
  81. IMPLEMENT_DYNAMIC(CArchiveException, CException)
  82. /////////////////////////////////////////////////////////////////////////////