I have run into an issue where I have to override Object's toString() method, but the original method doesn't throw any exceptions. However, I am using some generic code that requires exceptions to be thrown.
public String toString() throws EmptyListException, InvalidPositionException
{
Position<Entry<E>> current = fList.first();
StringBuilder str = new StringBuilder();
for(int i = 0; i < size(); i++)
{
try
{
str.insert(str.length(), current.element().toString() + " ");
current = fList.next(current);
}
catch(Exception e){}
}
return str.toString();
}
This is part of FavoriteList.java. These exceptions HAVE to be thrown. If there is any way to somehow suppress these exceptions or catch them inside the method, that would be helpful.
In the end, my method header has to look like this:
public String toString()
{ content }
I don't care about the ending content of the method. As long as it compiles I am fine. I just need to fix the header, but I can't find a way to fix it. Thank you very much in advance.