Q:

Get DIY Linked List Class to throw exception

So I've made a LinkedList class from scratch. My append(Object o) method adds an object to the end of a list, prepend(Object o) adds an object to the beginning and indexOf(Object o) returns the index of given object. 
The only thing I can't get to work is my get(int i) method.
Well, that's false. It works properly. It returns the object at the given index in the list, like I want it to. The only problem is that it won't catch IndexOutOfBounds exceptions.
public class LinkedList {

    //node class
    public class Node {
        public Object data;
        public Node next;
        public Node (Object data) {
            this.data = data;
        }
    }

    //variables
    protected Node head;

    //after this is my append, prepend, etc methods but they aren't important

    public Object get(int index)    {
        if (index < 0)
        return null;

        Node current = null;

        try {
            if (head != null) {
                current = head.next;
                for (int i = 1; i < index; i++) {
                    if (current.next == null)   {
                        return null;
                    }
                    current = current.next;
                }
                if (current.data == null)   {
                    throw new IndexOutOfBoundsException();
                }
                else
                    return current.data;
            }
        }
        catch (IndexOutOfBoundsException e) {
            System.out.println("Warning: Index out of bounds");
        }
        return current;
    }

I don't want this code to return null if there is no element at index i but to catch the exception. However, it won't catch the exception no matter what I do. Please help me pinpoint and fix what is wrong. Thank you!

A:

Your loop returns early because you perform the following check:
if(current.next == null) {
    return null;
}

