Description, NativeError, Number, Source, and SQLState Properties Example (VJ++)

Microsoft ActiveX Data Objects (ADO)

Description, NativeError, Number, Source, and SQLState Properties Example (VJ++)

This example triggers an error, traps it, and displays the Description, HelpContext, HelpFile, NativeError, Number, Source, and SQLState properties of the resulting Error object.

// The WFC class includes the ADO objects.

import com.ms.wfc.data.*;
import java.io.* ;

public class DescriptionX
{
    // The main entry point for the application.

    public static void main (String[] args)
    {
        DescriptionX();
        System.exit(0);
    }

    // DescriptionX function

    static void DescriptionX()
    {

        // Define ADO Objects.
        Connection cnConn1 = null;

        try
        {
            // Intentionally trigger an error.
            cnConn1 = new Connection();
            cnConn1.open("nothing");
        }
        catch( AdoException ae )
        {
            // Notify user of any errors that result from ADO.
            PrintProviderError(cnConn1);
        }

    }

    // PrintProviderError Function

    static void PrintProviderError( Connection Cnn1 )
    {
        // Print Provider errors from Connection object.
        // ErrItem is an item object in the Connection’s Errors collection.
        com.ms.wfc.data.Error  ErrItem = null;
        long nCount = 0;
        int  i      = 0;

        nCount = Cnn1.getErrors().getCount();

        // If there are any errors in the collection, print them.
        if( nCount > 0);
        {
            // Collection ranges from 0 to nCount - 1
            for (i = 0; i< nCount; i++)
            {
                ErrItem = Cnn1.getErrors().getItem(i);
                System.out.println("\t Error number: " + ErrItem.getNumber()
                    + "\t" + ErrItem.getDescription() );
            }
        }

    }

    // PrintIOError Function

    static void PrintIOError( java.io.IOException je)
    {
        System.out.println("Error \n");
        System.out.println("\tSource = " + je.getClass() + "\n");
        System.out.println("\tDescription = " + je.getMessage() + "\n");
    }
}