LDAP defines many result codes to deal with conditions
other than success. The ResultCode
class encapsulates the
LDAP codes and additional client-side codes specific to the SDK.
Your application deals with most non-success result codes when it
catches one of the LDAP SDK exceptions corresponding to the operation you
requested. ErrorResultException
is a common way for the
SDK to indicate a non-successful result. Your application can then take
remedial action based on the result code, as in the following synchronous
excerpt.
final LDAPConnectionFactory factory = new LDAPConnectionFactory(host, port); Connection connection = null; try { connection = factory.getConnection(); connection.bind(name, password); // Perform operations on the connection... } catch (final ErrorResultException e) { // Take remedial action based on the result code... // e.getResult().getResultCode() returns the code for you to interpret. } finally { if (connection != null) { connection.close(); } }
Also notice the methods ResultCode.getName()
that
provides a short, human-readable version of the result code, and
Result.getDiagnosticMessage()
that can also help debug
problems after the fact.