I retrieve data from twitter. I ve stored some ids in a database and I am trying to retrieve informations with twitter API. I am using the following code:
if(cursor.hasNext()){
try {
while (cursor.hasNext()) {
final DBObject result = cursor.next();
JSONObject features = new JSONObject();
//System.out.println(result);
Map<String, Object> value = (Map<String, Object>) result.get("user");
boole.add((Boolean) value.get("default_profile"));
boole.add((Boolean) value.get("default_profile_image"));
features.put("_id", value.get("id"));
...
}
catch (JSONException e) {
System.err.println("JSONException while retrieving users from db: " + e);
} catch (TwitterException e) {
// do not throw if user has protected tweets, or if they deleted their account
if (e.getStatusCode() == HttpResponseCode.UNAUTHORIZED || e.getStatusCode() == HttpResponseCode.NOT_FOUND) {
} else {
throw e;
}
}
I add twitter Exception since I cant retrieve data from some users due to authentication issues. However when my code reach catch (TwitterException e) it automatically stop running. I want to continue to the next cursor (next database's id)
It is because you have try catch block around your loop, so when exception is caught it falls out of the loop.
Placing try catch block inside while block will solve the problem.