Here is my code:

```
public E get(int index)
{
    LLNode<E> current = head;
    try {
        for (int i = 0; i <= index; i++) {
            if (current != null) {
                current = current.next;
            }
        }
        return current.data;
    } catch (IndexOutOfBoundsException e) {
        throw e;
    } catch (NullPointerException e) {
        // How do I handle this?
    }
}

```

How do I handle the `NullPointerException` when I have to return something of type E?I am testing my code using JUtil. I am a beginner and am finding this part tough to understand, please help.

EDIT : I am testing this function using JUtil function whose (partial)code is given below :

```
// Test empty list, get() should throw an exception
try {
    emptyList.get(0);
    fail("Check out of bounds");
} catch (Exception e) {
}

```

here emptylist is an Empty List object created from a personally created LinkedList Class. How do I solve for this (//test empty list, get should throw an exception) as in this case the foremost mentioned get function returns NullPointerException? Please help me.

New Code : 

```
public E get(int index)
    {
        // TODO: Implement this method.
        LLNode<E> current = head;
        for(int i=0; i<=index; i++)
        {
            if(current != null)
            {
                current = current.next;
            }
            else
            {
                throw new IndexOutOfBoundsException();
            }
        }
        return current.data;
    }

```

After running "New Code", these are the results and errors are on the bottom left panel :
[![After running tests on new code](https://i.stack.imgur.com/tvfBy.png)](https://i.stack.imgur.com/tvfBy.png)