Using try method to check existence of key in hash