Support Topics Documentation Slack YouTube Blog

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>>(){
                         @Override
                         public void handleResponse( List<Map> foundDevices )
                         {
                     
                             if (foundDevices.size() > 0){
                                ...// do something
                            }


                         }
                         @Override
                         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(AsyncTask.java:318)
at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:354)
at java.util.concurrent.FutureTask.setException(FutureTask.java:223)
at java.util.concurrent.FutureTask.run(FutureTask.java:242)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
at java.lang.Thread.run(Thread.java:762)
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(Invoker.java:122)
at com.backendless.core.responder.AdaptingResponder.responseHandler(AdaptingResponder.java:79)
at weborb.client.ioEngine.HttpIOEngine.processAMFResponse(HttpIOEngine.java:289)
at weborb.client.ioEngine.HttpIOEngine.send(HttpIOEngine.java:210)
at weborb.client.ioEngine.HttpIOEngine.invoke(HttpIOEngine.java:140)
at weborb.client.WeborbClient.invoke(WeborbClient.java:138)
at com.backendless.Invoker.invokeSync(Invoker.java:95)
at com.backendless.Invoker.invokeSync(Invoker.java:107)
at com.backendless.Messaging.getRegistrations(Messaging.java:249)
at com.backendless.Messaging.getDeviceRegistration(Messaging.java:244)

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.