Compiler Error J0126

'catch' block used without 'try' statement

The compiler detected a catch statement but did not find a corresponding try statement. In order to use a catch statement you must have a try statement preceding it. Ensure that you have a valid try statement preceding your catch statement and compile again.

The following example illustrates this error:

public class Simple {
   
   public void method1() {
   
      catch {
         // error: missing corresponding try statement
      }
   }
}

The following example illustrates the proper usage of the catch block:

public class Simple {
   
   public void method1() {
      try{
         //do something here
      }
      catch (Exception e){
         //handle exceptions from try statement here
      }
   }
}