As explained in the Error Handling page, the Java class methods may return no value (void), a
longvalue representing an object’sautoid, or abooleanvalue 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
truereturned by the Cursor methodsearch()causes execution of thefor()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 objectautoidwill be returned from Connection methodinsert().Fatal Error Handling
However, whenever a fatal error occurs, an exception will be thrown indicating the source of the error. Wherever appropriate,
try-catchblocks should be used to manage these exceptions as DatabaseError objects whoseerrorCodeproperty contains the integer value error code. The meaning of these return codes is defined inmco.h. (Please refer to the C API Return Codes for a complete list.)For example, following is a typical
try-catchblock 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; } }