Skip Headers

# Handling Exceptions

Previous

Next

Most exceptions in queries are database exceptions, resulting from a failure in the database operation (see "Database Exceptions (4002 – 4018)"). Write operations can also throw an `OptimisticLockException` on a write, update, or delete operation in applications that use optimistic locking. To catch these exceptions, execute all database operations within a `try`-`catch` block:

        try {
            Vector employees = session.readAllObjects(Employee.class);
        }
        catch (DatabaseException exception) {
            // handle exception
        }

See TopLink Workbench Error Reference for more information about exceptions in a TopLink application.