Error Handling: Try-Catch

It's a good practice to put code that can throw an exception inside try.. catch block. This is a general good practice and not specific to Appery.io Server Code. Learn more about JavaScript try-catch.

Example

The following code shows an example of try...catch block when updating a user in the database:

try{
   var user = DatabaseUser.update(
      db_id, 
      user_id,
      {"username":username,"email": email},
      userToken
   ); 
} catch(e){
   Apperyio.response.error(
      {error: e.toString()}, 
      "application/json"
   );
}