make key generation throw exceptions in case of errors