Closed bremersee closed 3 years ago
The throwIf
functionality was designed to propagate exceptions out of the handle for those who prefer to use a try-catch paradigm.
try {
DeleteOperation.builder()
.factory(getConnectionFactory())
.throwIf(ResultPredicate.NOT_SUCCESS)
.onResult(result -> System.out.println("onResult = " + result.getResultCode()))
.onException(ldapException -> System.out.println("onException = " + ldapException.getResultCode()))
.build()
.execute(DeleteRequest.builder()
.dn("cn=notexists,dc=...")
.build());
} catch (LdapException ldapException) {
System.out.println("catchException = " + ldapException.getResultCode())
}
If you prefer your implementation in a lamda, onResult
should give you what you want. Note that using throwIf
requires a synchronous style of programming as you must wait in the try block until a result is received.
Many thanks for the answer. That fits my observations. But also when using "execute", "onException" / the ExceptionHandler is not called. Is it even called?
BTW: The async approach is great! 👍
onException gets invoked when something unusual happens, never for normal server responses.
I execute an operation and expect, that the exception handler is called, because the entry doesn't exist. But it isn't called.
Example:
The current output is:
Expected output: