title: Getting an error using keyword throw in java
body: <pre><code>import java.io.*;
  class A {
       private static final int x = 5;
       private int y;
       A(int z)
       {
         y = z;
       }
  
       public void f()
       {
          if(y&lt;=x)
          {
             throw(-1);
          }
       }
  }
  
  
  public static void main(String args [])
  {
        A a = new A(2);
        try (a.f();)
        catch (int i){
            System.out.println("exception");
            }   
  }
  </code></pre>
  
  <p>I am fairly new to java and was trying to learn exception handling. I was just wondering what's wrong with this approach i have because i am getting an error, and how can i fix it?</p>