eXtremeDB Error Handling in Java

As explained in the Error Handling page, the Java class methods may return no value (void), a long value representing an object’s autoid, or a boolean value representing success or failure. Normal handling of these return codes is straight forward. For example:

 
    if (cursor.search(Cursor.Operation.GreaterThan, search_value)) 
    {
        for (Obj o : cursor) 
        {
            Console.Write("(" + o.value + ") ");
        }
    }
     

Here the boolean true returned by the Cursor method search() causes execution of the for() loop.

And:

 
    @Persistent(autoid = true)
    class Department
    {
        @Indexable(Type=Database.IndexType.BTree, unique=true)] // Declare unique tree index by "code" field
        public String code;
        public String name;
    }
    ...
     
    long autoid = con.insert(dept);
     

Here the definition of class Department with attribute @Persistent(autoid = true) indicates that the object autoid will be returned from Connection method insert().

Fatal Error Handling

However, whenever a fatal error occurs, an exception will be thrown indicating the source of the error. Wherever appropriate, try-catch blocks should be used to manage these exceptions as DatabaseError objects whose errorCode property contains the integer value error code. The meaning of these return codes is defined in mco.h. (Please refer to the C API Return Codes for a complete list.)

For example, following is a typical try-catch block for handling possible errors opening a database:

 
    try
    {
        db.open("opendb", params, devs); // Open In-Memory database.
        showRuntimeInfo(db2);
    }
    catch (DatabaseError dbe)
    {
        // Code 66 means duplicate instance. Valid case for SHM configuration
        if (dbe.errorCode != 66)
        { 
            throw dbe;
        }
    }