I am working on a method which gets elements out of a double linked deque. When the linkedlist is empty, I get a nullpointerexception and I am trying to figure out how to handle it. I am using to following code but it still requires me to return A. Any ideas how I can get to this compile?
def peekBack():A = {
try {
last.data // return if the list is full if not, catch the nullpointerexception
} catch {
case ex: NullPointerException => {
println("There are no elements in this list.")
//Error is here, it is requiring me to return something!!!
}
}
}
Thanks!