Added error handling in catch statement