0

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);} 
3
  • 1
    If it doesn't get to the next statement, it means you were catching the wrong exception. Commented Dec 17, 2013 at 19:29
  • 1
    what do you mean it does not continue? It is supposed to continue (besides the log). Is there an error in the second try? Commented Dec 17, 2013 at 19:29
  • I realise i was not catching the correct exception Commented Dec 17, 2013 at 19:32

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

4 Comments

I assume it is safer to use Exception e instead of specific exception to ensure everything is caught
It's even smarter to show ui notification with exception details inside catch
Well, I see that you use JavaFX. Here you can find an example of PopupWindow: gist.github.com/jewelsea/1926196 Just put the proper code inside catch block
Use e.getMessage() for getting exception details
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.