[ Pobierz całość w formacie PDF ]
.TABLE D.2.THE CArchiveException m_cause CODE VALUES.Cause Code MeaningCArchiveException::none No error occurred.CArchiveException::generic The specific cause wasn t specified.CArchiveException::badSchema The wrong version of an object was read.CArchiveException::badClass The class of the object being read was unexpected.CArchiveException::badIndex The file format is invalid.continues 032 31240-9 APP D 4/27/00 1:08 PM Page 672672 Appendix DTABLE D.2.CONTINUEDCause Code MeaningCArchiveException::readOnly Attempt to write on an archive opened for loading.CArchiveException::writeOnly Attempt to read on an archive opened for storing.CArchiveException::endOfFile The end of the file was reached unexpectedly while reading.Using the Database ExceptionsThere are two database exception classes: CDBException is used for ODBC-based data-base access, and CDAOException is used for DAO-based database access.You can throwthese exceptions yourself with the AfxThrowDBException() function, which needs threeparameters.The first, nRetCode, specifies one of a huge number of database return codesto define the type of error (you should look in the ODBC documentation for these).Thesecond parameter, pDB, is a pointer to the database associated with the exception, andthe third parameter, hstmt, is an ODBC handle to the SQL statement object that wasexecuted, causing the exception.The RETCODE type is available from the CDBException object via its m_nRetCode member.You can also access a human-readable piece of error text from the m_strError memberstring and the error text returned from the ODBC driver itself in them_strStateNativeOrigin member.The CDAOException class has a corresponding AfxThrowDaoException() function thatcan throw the DAO exception objects.This function needs just two optional parameters.The first, nAfxDaoError, is a DAO-specific error code that indicates problems with DAOitself (see Table D.3).The second parameter is an OLE SCODE value that is the returncode from a DAO-based OLE call (see the section  Using OLE Exceptions for a defini-tion of SCODEs).TABLE D.3.DAO COMPONENT-SPECIFIC ERROR CODES FROM nAfxDaoError.Error Code MeaningNO_AFX_DAO_ERROR The exception was due to a DAO-specific problem;you should check the supplied CDaoErrorInfo objectand SCODE value.AFX_DAO_ERROR_ENGINE_INITIALIZATION The Microsoft Jet Engine database engine failed dur-ing initialization.AFX_DAO_ERROR_DFX_BIND A DAO record set field exchange address is invalid.AFX_DAO_ERROR_OBJECT_NOT_OPEN The queried table hasn t been opened. 032 31240-9 APP D 4/27/00 1:08 PM Page 673Understanding and Exception Handling 673The CDAOException class has three member attributes: m_scode, which holds an asso-ciated OLE SCODE value with the attempted operation; or S_OK, if the OLE operation wassuccessful.The m_nAfxDaoError member holds one of the DAO-specific values fromTable D.3.The m_pErrorInfo is a pointer to a CDaoErrorInfo structure that holds anerror code, descriptive error strings, and a help context ID that is defined like this:struct CDaoErrorInfo{long m_lErrorCode;CString m_strSource;CString m_strDescription;CString m_strHelpFile;long m_lHelpContext;};By interrogating this structure, you can find most of the specific database error detailspertaining to the DAO exception.DAO exceptions can describe more than one error at a time, so you can use theGetErrorCount() member function to find out how many are being referenced.Theseother errors can then be obtained by passing the GetErrorInfo() function a zero-basedindex to the specific error.After calling GetErrorInfo() with a specific index in theDrange returned by the GetErrorCount() function, m_pErrorInfo will be updated topoint to the specified object, and thus you can retrieve those values.Using OLE ExceptionsThere are two types of OLE exceptions, represented by two classes: the COleExceptionclass, which is normally used for server-side or OLE-specific operations, and theCOleDispatchException class, which is used when dealing with client-side IDispatch-based operations such as calling ActiveX object functions.The simpler of the two is the COleException class, which can be generated by callingthe AfxThrowOleException() function passing an OLE SCODE value.An OLE SCODEis a 32-bit error code that is used to represent any kind of error arising from an OLEfunction.This value would probably arise from the return code of a function call to a function onone of the interfaces of an OLE object.This SCODE value will then be stored in theexception s m_sc member for analysis from within a catch block.There is also a Process() static member function that is passed an exception object andwill turn that exception into an SCODE value to represent that exception. 032 31240-9 APP D 4/27/00 1:08 PM Page 674674 Appendix DThe COleDispatchException class is used in conjunction with OLE IDispatch inter-faces and is thrown by the AfxThrowOleDispatchException() function.This functionhas two forms, both with two mandatory parameters and an optional parameter.The firstparameter for both forms is a wCode WORD value that is an application-specific error code.The second parameter is an lpszDescription string pointer in one form, ornDescriptionID for a UINT resource code; both types represent either a verbal string or astring resource code for a verbal string describing the error.The last optional parameteris a help context ID.These values are then available as member variables of the COleDispatchExceptionobject via m_wCode, m_strDescription, and m_dwHelpContext.If a help context is speci-fied and a help file available, the framework will fill in an m_strHelpFile string identi-fying the help file.The name of the application producing the error can also be soughtfrom the m_strSource attribute.If you raise this exception from an OLE object such as an ActiveX control, Visual Basicor any other application using the control or object will display these exception details [ Pobierz całość w formacie PDF ]
  • zanotowane.pl
  • doc.pisz.pl
  • pdf.pisz.pl
  • agnieszka90.opx.pl