title: Throw exception if method arguments are invalid
body: <p>I am kind of new to java so pardon this rather simple question, I guess. This method will count how many digits are there on a <strong>POSITIVE</strong> integer only. So it needs to throw an error to the caller. How do I do so when the input is negative, I throw an error and exit the method without returning anything?</p>
  
  <pre><code>public static int countDigits(int n)
      {
          if (n&lt;0)
          {
              System.out.println("Error! Input should be positive");
              return -1;
          }
          int result = 0; 
          while ((n/10) != 0)
          {
              result++;
              n/=10;
          }
          return result + 1;
      }
  </code></pre>