Trouble handling a BackendlessException code:5000

Hi guys,

Not quite sure what I am doing wrong with my error handling here, but if I deliberately put in a wrong device id which I know doesn’t exist in the deviceRegistration table then I was expecting it to be handled in the handleFault block and the program code continue. Instead it just crashes the app and I can’t seem to handle it. Is there anything wrong with the code below.

             String whereClause = "deviceId ='" + deviceID +"'";
             DataQueryBuilder queryBuilder = DataQueryBuilder.create();
             queryBuilder.setWhereClause( whereClause );

             Backendless.Data.of( "DeviceRegistration" ).find( queryBuilder,
                     new AsyncCallback<List<Map>>(){
                         public void handleResponse( List<Map> foundDevices )
                             if (foundDevices.size() > 0){
                                ...// do something

                         public void handleFault( BackendlessFault fault )
                             // an error has occurred, the error code can be retrieved with fault.getCode()
                             System.out.println("an error occurred trying to retrieve a device");


Here is the debug info:
2019-07-23 08:58:41.052 17026-18446/com.app1 E/AndroidRuntime: FATAL EXCEPTION: AsyncTask #3
Process: com.app1, PID: 17026
java.lang.RuntimeException: An error occurred while executing doInBackground()
at android.os.AsyncTask$3.done(
at java.util.concurrent.FutureTask.finishCompletion(
at java.util.concurrent.FutureTask.setException(
at android.os.AsyncTask$SerialExecutor$
at java.util.concurrent.ThreadPoolExecutor.runWorker(
at java.util.concurrent.ThreadPoolExecutor$
Caused by: BackendlessException{ code: ‘5000’, message: ‘Unable to retrieve device. Invalid device ID.’, extendedData: ‘{}’, detail: ‘Unable to retrieve device. Invalid device ID.’ }
at com.backendless.Invoker$SyncResponder.errorHandler(
at com.backendless.core.responder.AdaptingResponder.responseHandler(
at weborb.client.ioEngine.HttpIOEngine.processAMFResponse(
at weborb.client.ioEngine.HttpIOEngine.send(
at weborb.client.ioEngine.HttpIOEngine.invoke(
at weborb.client.WeborbClient.invoke(
at com.backendless.Invoker.invokeSync(
at com.backendless.Invoker.invokeSync(
at com.backendless.Messaging.getRegistrations(
at com.backendless.Messaging.getDeviceRegistration(

Hello @mike-turner

You should not get an error when you do a deviceID search; you should get an empty list.

I tested your code, and I went into the HandleResponse section and get empty list.

Perhaps you get an error elsewhere?

Well thats what I thought should happen but the error is caused by BackendlessException 5000 according to trace? No matter, I will investigate further.