title: How to break and continue a try-catch inside a while loop?
body: <p>There is a need to connect to LDAP using LDAPConnection using Java in a try-catch. When the initial connection cannot be established, i now want to create some logic to reattempt the connection after 1 minute for a max of 3 attempts. </p>
  
  <p>Current logic:</p>
  
  <pre><code>try {
        connect = new LDAPConnection(...);
  } catch (LDAPException exc) {
        //throw exception message
  }
  </code></pre>
  
  <p>Desired logic:</p>
  
  <pre><code>int maxAttempts = 3, attempts=0;
  while(attempt &lt; maxAttempts) {
       try {
           connect = new LDAPConnection(...);
           /*if connection can be established then break from loop, but keep connection alive*/
           break;
       } catch(LDAPException exc) {
              if(attempt == (maxAttempts-1)) {
                   //throw exception message
               }
               continue;
        }
  
       Thread.sleep(1000);
       attempt++;
  }
  </code></pre>
  
  <p>Is the code in my desired logic correct? I also wanted to be sure my break and continue statements are in the correct location in the loop.</p>