App breaking during try/catch block

0
Hello experts! I had a quick question regarding some java code that I wrote. I’m getting a payload from an external system and use the key values of this json structure to search for the corresponding attribute in an entity. I use a while loop to iterate over the keys and in case a key appears that I don’t have in the entity I catch this error and continue on iterating over the keys. Here is a typical structure from external system: {“name”: [“Thomas”], “lastname”: [“Mustermann”], “salutation”:[”prof”]} Here are the entity attributes: name, lastname And this is the main part of my code:         // Get mendix object and get the attributes of this object         IMendixObject user = TempUser.getMendixObject();                 // Iterate over user attributes -> find attribute names in JSON object returned from sytem and set the value         while( attrsKeys.hasNext() ) {             String key = attrsKeys.next();             JSONArray arr = attributes.getJSONArray(key);             try {                 user.setValue(this.context(), key, arr.getString(0));             } catch (Exception e) {                 System.out.format("%s does not exist as a variable\n", key);             }         } As you can see from the entity structure and the structure from the external system, there is one attribute too many. The catch block should though take care of this without breaking the while loop. At the very moment that I caught the exception the app seems to have restarted itself.  I’ve only had the case happen once so it’s not a major issue but I thought to ask anyway in case someone might have a way to improve my implementation or sees some best practice violation.  Thanks in advance, Andrew  
asked
0 answers