Throw specific exception and check if the attribute exists

And add test cases