0

given:

public void connect() {
    try {
        connect_to_server();
    } catch (ServerUnavailableException ex){
        System.out.print("server unavailable");
    }
}

I would like to try, and retry, connecting to the server 3 times before giving up.

I could put the entire try/catch in, say, a for loop, but would this fit with Java's 'Best Practices'. From what I recall on the topic, this would be a misuse of try/catch statements. Then again, I could be entirely wrong. What do you think?

ChaseTheSun
  • 3,810
  • 3
  • 18
  • 16

1 Answers1

0

It would be better if you implement connect_to_server() to throw exception after failing for the third time.

Also, method name as connectToServer() is convention in java.

TheKojuEffect
  • 20,103
  • 19
  • 89
  • 125