Compiler Error J0233

Catch clause is unreachable; exception 'identifier' is never thrown in the corresponding try block

The compiler detected that the specified catch clause will never be executed because the corresponding try statement block never throws the catch statement's exception type. Catch statements are required to catch exceptions or derivations of exceptions that the try statement block can throw. This error can be avoided by changing the catch statement so it does not catch a specific exception type, but instead, catches the base Exception class. Change the exception class your catch statement will trap and compile again.

The following example illustrates this error:

class Simple{
   void method1(){
      int I = 0;
      try{
         I = I + 1; //This try block has nothing to do with clones
      }
      catch (CloneNotSupportedException c){
         //error: The exception type can never be caused by try block
      }
   }
}

The following example illustrates how to avoid this error by using the base Exception class:

class Simple{
   void method1(){
      int I = 0;
      try{
         I = I + 1; //This try block has nothing to do with clones
      }
      catch (Exception e){
         //This is OK since all exceptions must derive from this class
      }
   }
}