import javax.swing.JOptionPane;
class DeclararExcepcion {
    public static void llenar ( int [] arreglo,int indice,int valor) 
      throws Exception {
        if ( indice < arreglo.length && indice >=0){
              arreglo[indice] = valor;
        } else {
          throw new Exception("Arreglo no llenado en celda: "+indice);
        }
    }
    public static void main(String [] args) {
        int [] arreglo =new int[3]; 

        try {
         for (int i=0;i<=3; i++)
            DeclararExcepcion.llenar(arreglo,i,i*2); 
        } catch (Exception excepcion) {
           JOptionPane.showMessageDialog(null,excepcion.getMessage());
        }
    }

}