added try catch for ArrayIndexOutOfBoundsException and handled exception