Catching error when testing for key