NoSuchElementException would be thrown when you are trying to read a line/value that is not present in the source. One scenario would be when you try to read content from a specific line from a file, this exception would occur. To handle this just catch NoSuchElementException and return a proper message.

Read more of this post