Try-Catch-Throw in the same Java class

Posted by Carlos on Stack Overflow See other posts from Stack Overflow or by Carlos
Published on 2010-03-07T01:17:40Z Indexed on 2010/03/08 20:36 UTC
Read the original article Hit count: 402

Is it possible to catch a method in the current class the try-catch block is running on? for example:

  public static void arrayOutOfBoundsException(){
      System.out.println("Array out of bounds");
  }

    .....

  public static void doingSomething(){
    try
    {
       if(something[i] >= something_else);
    }
    catch (arrayOutOfBoundsException e)
    {
       System.out.println("Method Halted!, continuing doing the next thing");
    }
  }

If this is possible how will it be the correct way to call the catch method?

If this is not possible, could anyone point me in the right direction, of how to stop an exception from halting my program execution in Java without having to create any new classes in the package, or fixing the code that produces ArrayOutOfBoundsException error.

Thanks in Advance,

A Java Rookie

© Stack Overflow or respective owner

Related posts about java

Related posts about try-catch-throw