I have added exception handling to solve that case. Please advise if there is a better way to do it.