title: switch case programming practice
body: <pre><code>enum SQLErrorCode{
        OK = 0,
        PARTIAL_OK = 1,
        SOMEWHAT_OK = 2,
        NOT_OK = 3,
  };
  </code></pre>
  
  <p><strong>Code 1:</strong></p>
  
  <pre><code>int error = getErrorCode();
  if((error == SQLErrorCode.PARTIAL_OK) ||
    (error == SQLErrorCode.SOMEWHAT_OK) ||
    (error == SQLErrorCode.NOT_OK) ||
    (error &lt; 0))
     callFunction1();
  else
      callFunction2();
  </code></pre>
  
  <p><strong>Code 2:</strong></p>
  
  <pre><code>switch(error){
         case SQLErrorCode.PARTIAL_OK: 
                                      callFunction1();
                                      break;
          case SQLErrorCode.SOMEWHAT_OK:
                                      callFunction1();
                                      break;
          case SQLErrorCode.NOT_OK: 
                                      callFunction1();
                                      break;
          default:
                                      callFunction2();
                                      break;
  }
  </code></pre>
  
  <p>Which method should I prefer. As far as performance is considered there should not be much difference. How to handle error &lt; 0 condition in switch case.</p>
  
  <p>EDIT:
  Joel's solution:</p>
  
  <pre><code>switch(error) {
       case SQLErrorCode.PARTIAL_OK: 
       case SQLErrorCode.SOMEWHAT_OK:
       case SQLErrorCode.NOT_OK: 
           callFunction1();
           break;
       case SQLErrorCode.OK:
           callFunction2();
           break;
       default:     // error &lt; 0 is handled
           callFunction1();
           break;
  }
  </code></pre>
  
  <p><strong>Q.</strong> error &lt; 0 is handled. If I have to handle other numbers in error which do not belong to any of the cases here including default.</p>