Sin categoría

Error handling in the Java client library

Lectura de 3 minutos

En mi previous blog article, we looked at the errors thrown by libCouchbase clients such as ruby, python, C and C++. This blog will focus on the Java client library for Couchbase.

In the Java client library, there are exceptions, no errors. Depending on the return type and state of application, different exceptions can be thrown by the java client. Generally, you’ll find those exceptions noted either through the @throws annotations or your IDE will tell you that you need to catch them.

Here are some exceptions that you might encounter when using the Java library:

All asynchronous operations return futures, they do not raise an exception until you block on the result. In addition to trapping the exception, you can also inspect the status of the future and use the getMessage() API to obtain the actual message text.

For synchronous APIs, the client library is implemented as a wrapper around the async methods. Here are the most common exceptions thrown by the syncronous java APIs :

1.     TimeoutException – This means that waiting on the future took longer than expected. For example, this exception is thrown if get() is used with a default timeout value and it expires. It is also thrown if get() with a custom timeout is used and the timeout expires.

2.     CancellationException – This means that the operation was cancelled while “in flight”. For example, a request sent over a network without a reply. This can particularly happen when a node fails. All operations that are currently in flight are cancelled.

3.     InterruptedException– This means that there was a interrupt while blocking on the future.

If you are using views in your application with Java, you might see the following exceptions :

1.    InvalidViewException – This means that an invalid view name or design document was specified. This exception is also thrown if a view is in the development stage and is not deployed to production or the view is in production and the app refers to the development view.

To handle this exception, try using the correct viewname parameter when calling the view and make sure that this view is deployed to production.

If you are using the APIs to verify that your data is persisted by Couchbase, there are a few more exceptions you might want to watch out for:

1.    ObservedException – This means that something general went wrong with API call and more details can be found in the status message.

2.    ObservedTimeoutException – This means that the API call timed out and you must retry.

3.    ObservedModifiedException – This means that the API call failed because the document was modified in the meantime. This indicates a race condition.

Finally, during bootstrapping your application with the Java API you may encounter the following exceptions:

1.    ConfigParsingException – This means that the current configuration cannot be parsed. You must verify the correctness of your config file and try again.

You may also see other network exceptions if the host is not reachable.

Good luck building your applications using the Couchbase Java client. If you have any questions, please do not hesitate to ask us in the forums.

Compartir este artículo

Autor

Don Pinto es un director principal de gestión de productos en Couchbase y actualmente se enfoca en avanzar las capacidades de Couchbase Server. Es un apasionado de la tecnología de datos y en el pasado ha escrito varios artículos sobre Couchbase Server, incluyendo blogs técnicos y documentos técnicos informativos (white papers). Antes de unirse a Couchbase, Don pasó varios años en IBM, donde desempeñó el rol de desarrollador de software en el grupo de gestión de información de DB2 y, más recientemente, como gerente de programas en el equipo de SQL Server en Microsoft. Don tiene una maestría en informática y una licenciatura en ingeniería informática de la Universidad de Toronto, Canadá.

Deja un comentario

¿Listo para comenzar con Couchbase Capella?

Comenzar a construir

Visita nuestro portal para desarrolladores para explorar NoSQL, consultar recursos y comenzar con los tutoriales.

Usa Capella gratis

Empieza a usar Couchbase en tan solo unos clics. Capella DBaaS es la forma más fácil y rápida de comenzar.

Ponte en contacto

¿Quieres saber más sobre las ofertas de Couchbase? Permítenos ayudarte.