Reputation: 2433
How can I resume code shown below, so that if the first try gets an exception the code execusion will still carry on to the 2nd try. at the moment, if I get an exception on the first try, the code does not continue to the next try below it.
Calendar facebook_check_post_date = Calendar.getInstance();
facebook_check_post_date.add(Calendar.DAY_OF_MONTH, -4);
long facebook_check_post_Unix_Time = facebook_check_post_date.getTimeInMillis() / 1000;
String query = "SELECT message,timeline_visibility, created_time FROM stream WHERE source_id = 187050104663230 AND message AND strlen(attachment.fb_object_type) < 1 AND type != 56 AND type = 46 AND strpos(message, \"prayer time(s)\") < 0 AND strpos(message, \"White days\") < 0 AND strpos(message, \"Hadith of the Day:\") < 0 AND created_time > " + facebook_check_post_Unix_Time + "LIMIT 1";
try
{
List<JsonObject> queryResults = facebookClient.executeFqlQuery(query, JsonObject.class);
facebook_post = queryResults.get(0).getString("message");
facebook_post_visibility = queryResults.get(0).getString("timeline_visibility");
facebook_Label_visible = true; facebook_created_time_calendar.setTimeInMillis(queryResults.get(0).getLong("created_time")* 1000);
out.print("Comment posted on:");
out.println(facebook_created_time_calendar.getTime());
}
catch (FacebookException e){Logger.getLogger(JavaFXApplication4.class.getName()).log(Level.SEVERE, null, e);}
query = "SELECT fan_count FROM page WHERE page_id = 187050104663230";
try
{
List<JsonObject> queryResults = facebookClient.executeFqlQuery(query, JsonObject.class);
facebook_Fan_Count = queryResults.get(0).getString("fan_count");
out.println(facebook_Fan_Count);
}
catch (FacebookException e){Logger.getLogger(JavaFXApplication4.class.getName()).log(Level.SEVERE, null, e);}
Upvotes: 0
Views: 98
Reputation: 1121
you need to put the code within the second try block in a method. invoke this method from the catch block of the first try.
have a look at this Continue Execution even after program catches exception
Upvotes: 0
Reputation: 749
Try to use Exception instead of FacebookException:
Calendar facebook_check_post_date = Calendar.getInstance();
facebook_check_post_date.add(Calendar.DAY_OF_MONTH, -4);
long facebook_check_post_Unix_Time = facebook_check_post_date.getTimeInMillis() / 1000;
String query = "SELECT message,timeline_visibility, created_time FROM stream WHERE source_id = 187050104663230 AND message AND strlen(attachment.fb_object_type) < 1 AND type != 56 AND type = 46 AND strpos(message, \"prayer time(s)\") < 0 AND strpos(message, \"White days\") < 0 AND strpos(message, \"Hadith of the Day:\") < 0 AND created_time > " + facebook_check_post_Unix_Time + "LIMIT 1";
try
{
List<JsonObject> queryResults = facebookClient.executeFqlQuery(query, JsonObject.class);
facebook_post = queryResults.get(0).getString("message");
facebook_post_visibility = queryResults.get(0).getString("timeline_visibility");
facebook_Label_visible = true;
facebook_created_time_calendar.setTimeInMillis(queryResults.get(0).getLong("created_time")* 1000);
out.print("Comment posted on:");
out.println(facebook_created_time_calendar.getTime());
}
catch (Exception e) {
Logger.getLogger(JavaFXApplication4.class.getName()).log(Level.SEVERE, null, e);
}
query = "SELECT fan_count FROM page WHERE page_id = 187050104663230";
try
{
List<JsonObject> queryResults = facebookClient.executeFqlQuery(query, JsonObject.class);
facebook_Fan_Count = queryResults.get(0).getString("fan_count");
out.println(facebook_Fan_Count);
}
catch (Exception e){
Logger.getLogger(JavaFXApplication4.class.getName()).log(Level.SEVERE, null, e);
}
Hope it helps
Upvotes: 1