Synchronous method error handling /return info

I used the data , files and relation ship using asynchronous methods and all look great.
I have decided to go with synchronous methods as I need to execute things sequentially in an AsyncTask
My question is about the return values. It is pretty organized and well documented with the asynchronous calls as pretty much it is either success or you get backendlessfault which you can get more info about .
But for synchronous calls , I found that data saving gives you map , while relationship gives you an integer while files don’t return anything but throws an exception you have to handle
How do I know what each one error situation should do ? Basically how do I know if

  • there is an error and the call failed
  • the reason for the failure
    Thank you

Hi SnakeEyes

What Backendless are you using 3.x or 4.x?, and what SDK are you using JS, JAVA, …?

And could you please show us a part of your code where you use Sync/Async methods

Thanks, Vlad


I am using Android on 4.x

try {
 Backendless.Files.Android.upload( bm, Bitmap.CompressFormat.JPEG, 100,fileName, "media");
 Map returnedMap = Backendless.Data.of(GlobalVar.TABLES.BK_TABLE.TABLE_NAME).save(map);
HashMap<String, Object> parentObject = new HashMap<String, Object>();
parentObject.put( GlobalVar.TABLES.BOOK_TABLE.OBJECTID, tempBook.getObjectId() );
HashMap<String, Object> childObject = new HashMap<String, Object>();
childObject.put( GlobalVar.TABLES.USER_TABLE.OBJECTID, GlobalVar.myUser.getUserObjectId() );
ArrayList<Map> children = new ArrayList<Map>();
children.add( childObject );
Integer result = Backendless.Data.of( GlobalVar.TABLES.BK_TABLE.TABLE_NAME ).setRelation( parentObject, GlobalVar.TABLES.BK_TABLE.PUBLISHER, children);
} catch (Exception e) {
 Toast.makeText( getActivity(), e.getMessage(), Toast.LENGTH_SHORT ).show();

As you can see, I am using these methods but I have no idea what the return types means and how to check for error

Did you see the “Error Handling” section in the doc:?

When you say you have no idea what the return types mean, which API in particular are you talking about?

Hi Mark,

Yes I checked that. It only refers to situations where BackendFaultException is thrown. Only the Data API with method “save” throws that type of exception (from the above code snippet).

For example, the Files ->Upload method throws Exception (not BackendFaultException)
The Data->SetRelation method does not throw an exception at all. It just returns an integer specifying the number of relations but I don’t know if this returned value will hold another info such as errorCode in case of errors

If all the synchronous methods had the BackendlessFault Exception then that would’ve been consistent but it seems every method has its error handling way (and thus my question)

Actually ALL synchronous methods can potentially throw BackendlessException. Not all of them declare it for the reason that BackendlessException extends RuntimeException, thus it is not checked:

It is a good practice though to have a try/catch block around the sync calls and check for any potential error conditions.


OHHH That helps a lot then. Because when I was hovering over the method “setRelation” the documentation did not say that it throws any type of exception.

So I can surround the Files ->Upload and Data->SetRelation methods with ty/catch block for th BackendlessException which will catch errors if something goes wrong, correct?

Yes, that’s correct.

Java does not require methods to declare that they can throw runtime exceptions - that’s why you didn’t see it there. But if there is an error coming back from the server, it will be delivered through BackendlessException.