Udostępnij za pośrednictwem


Error Trapping

In databinding, error trapping comes from two sources: error events or error objects.

Error Trapping via Error Events

Both the ADO data control and the RDO RemoteData control data controls have error events. Typically, you set an error event handler. The event handlers have the following signature.

void CMyDlg::OnErrorAdodc1(long ErrorNumber,
                           BSTR* FAR Description,
                           long Scode,
                           LPCTSTR Source,
                           LPCTSTR HelpFile,
                           long HelpContext,
                           BOOL FAR* fCancelDisplay)

Usually the Description field is populated, but the ErrorNumber and Scode fields are only populated in the event of COM errors. A standard event handler is to display the Description field in a message box. For example:

{
   USES_CONVERSION;   
// note: have to include the ATL file ATLConv.h to use the ATL conversion macros
   ::AfxMessageBox(OLE2T(*Description), MB_OK);
}

However, because the ADO data control and RDO RemoteData control are already set up to trap error events, no coding is necessary.

Error Trapping Through Error Objects

Both ADO and RDO have error objects. When generating wrapper classes, the RDO RemoteData control generates wrappers for error objects, but the ADO data control does not.

The ADO data control automatically displays ADO error messages.

See Also

Reference

Databinding with ActiveX Controls in Visual C++