Share via


CDaoException Class

Represents an exception condition arising from the MFC database classes based on data access objects (DAO).

class CDaoException : public CException

Members

Public Constructors

Name

Description

CDaoException::CDaoException

Constructs a CDaoException object.

Public Methods

Name

Description

CDaoException::GetErrorCount

Returns the number of errors in the database engine's Errors collection.

CDaoException::GetErrorInfo

Returns error information about a particular error object in the Errors collection.

Public Data Members

Name

Description

CDaoException::m_nAfxDaoError

Contains an extended error code for any error in the MFC DAO classes.

CDaoException::m_pErrorInfo

A pointer to a CDaoErrorInfo object that contains information about one DAO error object.

CDaoException::m_scode

The SCODE value associated with the error.

Remarks

The class includes public data members you can use to determine the cause of the exception. CDaoException objects are constructed and thrown by member functions of the DAO database classes.

Note

The DAO database classes are distinct from the MFC database classes based on Open Database Connectivity (ODBC). All DAO database class names have the "CDao" prefix. You can still access ODBC data sources with the DAO classes. In general, the MFC classes based on DAO are more capable than the MFC classes based on ODBC; the DAO-based classes can access data, including through ODBC drivers, via their own database engine. The DAO-based classes also support Data Definition Language (DDL) operations, such as adding tables via the classes, without having to call DAO directly. For information on exceptions thrown by the ODBC classes, see CDBException.

You can access exception objects within the scope of a CATCH expression. You can also throw CDaoException objects from your own code with the AfxThrowDaoException global function.

In MFC, all DAO errors are expressed as exceptions, of type CDaoException. When you catch an exception of this type, you can use CDaoException member functions to retrieve information from any DAO error objects stored in the database engine's Errors collection. As each error occurs, one or more error objects are placed in the Errors collection. (Normally the collection contains only one error object; if you are using an ODBC data source, you are more likely to get multiple error objects.) When another DAO operation generates an error, the Errors collection is cleared, and the new error object is placed in the Errors collection. DAO operations that do not generate an error have no effect on the Errors collection.

For DAO error codes, see the file DAOERR.H. For related information, see the topic "Trappable Data Access Errors" in DAO Help.

For more information about exception handling in general, or about CDaoException objects, see the articles Exception Handling (MFC) and Exceptions: Database Exceptions. The second article contains example code that illustrates exception handling in DAO.

Inheritance Hierarchy

CObject

CException

CDaoException

Requirements

Header: afxdao.h

See Also

Reference

CException Class

Hierarchy Chart

CException Class