created a method to handle errors