Replace custom exception by KeyError