title: avoid Negative Array Size Exception with try, catch and throw
body: <p>The following Java code: </p>
  
  <pre><code>   public class SomeClass {
     int[] table;
     int size;
  
     public SomeClass(int size) {
        this.size = size;
        table = new int[size];
     }
  
     public static void main(String[] args) {
        int[] sizes = {5, 3, -2, 2, 6, -4};
        SomeClass testInst;
        for (int i = 0; i &lt; 6; i++) {
           testInst = new SomeClass(sizes[i]);
           System.out.println("New example size " + testInst.size);
        }
     }
  }
  </code></pre>
  
  <p>The first two instances of SomeClass, which have size 5 and 3, will be created without a problem. However, when the constructor SomeClass is called with an argument of -2, a run time error is generated: NegativeArraySizeException.</p>
  
  <p>how can i modify the above code so that it behaves more robustly by using try, catch and throw. The main method should catch this exception and print a warning message then continue execution of the loop.</p>
  
  <p>im a java newbie so would appreciate any help.</p>
  
  <p>thanks</p>