Added try block to handle the condition of no results from the database.