title: java errorhandling: how to check for numberformatexceptions
body: <p>I'm learning java and I'm trying to make a very simple application that does conversion of currency. You enter a rate, a direction (e.g : from euro to dollars or reverse) and an amount. the numbers valid non negative numbers.</p>
  
  <p>So far I managed to make it so that the number can't be negative; now I need to throw an error if it's not a number.
  I have following code:</p>
  
  <pre><code>public void setKoers(double koers) 
              throws NegativeValueException, NumberFormatException{
      if (koers &gt; 0 ) {
              this.koers=koers;
          } else {
              throw new NegativeValueException("negative number");
          }
  }
  </code></pre>
  
  <p>and my main looks like</p>
  
  <pre><code>    try   {
              cal.setKoers( Double.parseDouble(args[0])); 
  
            } catch(NegativeValueException e) {
               System.out.println(e.getMessage());
            } catch (NumberFormatException e) {
               System.out.println( e.getMessage());
            }
  </code></pre>
  
  <p>So how can I check if <code>koers</code> is a number or not.
  I know I could put try and catch the error in my code, but I think this would go against the logic of where and how to deal with errors: in my main function I should catch any <a href="http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/NumberFormatException.html" rel="nofollow">NumberFormatException</a></p>